Skip to content

Commit

Permalink
Add environment variable for CRON_SCHEDULE
Browse files Browse the repository at this point in the history
  • Loading branch information
CanardConfit committed Mar 9, 2024
1 parent c6e5bdc commit 51964ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ RUN apk add --no-cache git rsync openssh-client dcron tzdata
COPY backup-script.sh /backup-script.sh
RUN chmod +x /backup-script.sh

# Schedule the backup script to run daily at midnight using crontab
# Output is redirected to /var/log/cron.log for logging
RUN echo "0 0 * * * /backup-script.sh >> /var/log/cron.log 2>&1" > /etc/crontabs/root

# Create the log file to enable log output via 'docker logs'
RUN touch /var/log/cron.log

Expand All @@ -35,6 +31,13 @@ ENV GIT_REMOTE_URL=""
# This environment variable must be set externally.
ENV SSH_PRIVATE_KEY=""

# CRON_SCHEDULE defines when the backup script runs, defaulting to midnight every day.
# Use standard cron format (e.g., "0 0 * * *" for midnight).
ENV CRON_SCHEDULE="0 0 * * *"

# Configure crontab based on CRON_SCHEDULE environment variable
RUN echo "${CRON_SCHEDULE} /backup-script.sh >> /var/log/cron.log 2>&1" > /etc/crontabs/root

# ----------
# Entrypoint
# ----------
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This solution provides an automated way to back up a Git repository hosted on an

## Features

- **Scheduled Backups**: Leverages `dcron` to schedule daily backups at midnight (located in Dockerfile).
- **Scheduled Backups**: Leverages `dcron` to schedule daily backups at midnight by default (ENV variable `CRON_SCHEDULE`).
- **Environment Customization**: Allows configuration of source directory, commit message template, Git remote URL, and SSH private key through environment variables.
- **SSH Key Management**: Incorporates SSH setup for Git operations to securely connect to the remote repository.
- **Timezone Management**: Timezone configuration within the container.
Expand Down Expand Up @@ -42,6 +42,7 @@ services:
- git-volume:/git-repo/
environment:
TZ: Europe/Zurich
CRON_SCHEDULE: "0 0 * * *"
SOURCE_FOLDER_PATH: "/obsidian/"
COMMIT_MESSAGE_TEMPLATE: "Backup on CURRENT_DATE" # CURRENT_DATE is a placeholder
GIT_REMOTE_URL: "<Your_remote_ssh_git_repo>"
Expand Down

0 comments on commit 51964ab

Please sign in to comment.