Skip to content

Commit

Permalink
Add an option to choose whether data should be backed up as soon as t…
Browse files Browse the repository at this point in the history
…he container is launched
  • Loading branch information
christophetd committed Apr 23, 2018
1 parent 188fb95 commit 260af7a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ install:
- pip install awscli
script:
- docker build . -t duplicacy-autobackup
- bash test.sh
- for test in tests/*.sh; do echo "Running $test..."; bash $test; done
notifications:
email: false
env:
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ENV BACKUP_SCHEDULE='* * * * *' \
BACKUP_NAME='' \
BACKUP_LOCATION='' \
BACKUP_ENCRYPTION_KEY='' \
BACKUP_IMMEDIATLY='no' \
DUPLICACY_BACKUP_OPTIONS='-threads 4 -stats' \
DUPLICACY_INIT_OPTIONS='' \
AWS_ACCESS_KEY_ID='' \
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You need to provide credentials for the storage provider your of your choice usi
If you want to execute an out of schedule backup, you can do so by running the script `/app/backup.sh` inside the container :

```
$ docker exec duplicacy-autobackup /app/backup.sh
$ docker exec duplicacy-autobackup /app/duplicacy-autobackup.sh backup
```

## Example
Expand Down Expand Up @@ -121,6 +121,7 @@ More: see [Duplicacy's documentation](https://github.com/gilbertchen/duplicacy/w

Use the following environment variables if you want to customize duplicacy's behavior.

- `BACKUP_IMMEDIATLY` (`yes`/`no`): indicates if a backup should be performed immediatly after the container is started. Equivalent to launching the container and then running `docker exec duplicacy-autobackup /app/duplicacy-autobackup.sh backup`. By default, `no`.
- `DUPLICACY_INIT_OPTIONS`: options passed to `duplicacy init` the first time a backup is made. By default, `-encrypt` if `BACKUP_ENCRYPTION_KEY` is not empty.
- `DUPLICACY_BACKUP_OPTIONS`: options passed to `duplicacy backup` when a backup is performed. By default: `-threads 4 -stats`. **If you are backing up a hard drive (and not a SSD), it is recommended to use `-threads 1 -stats` instead** (see [here](https://duplicacy.com/issue?id=5670666258874368) for more details).

Expand Down
16 changes: 11 additions & 5 deletions backup.sh → duplicacy-autobackup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ export DUPLICACY_GCD_TOKEN=$GCD_TOKEN
export DUPLICACY_GCS_TOKEN=$GCS_TOKEN_FILE
export DUPLICACY_ONE_TOKEN=$ONEDRIVE_TOKEN_FILE

if [[ ! -d .duplicacy ]]; then
do_init
fi

do_backup
if [[ "$1" == "init" ]]; then
if [[ ! -d .duplicacy ]]; then
do_init
else
echo 'This folder has already been initialized with duplicacy. Not initializing again'
fi
elif [[ "$1" == "backup" ]]; then
do_backup
else
echo "Unknown command: $1" >&2
fi
10 changes: 8 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/sh
echo "$BACKUP_SCHEDULE /app/backup.sh" > /var/spool/cron/crontabs/root
/app/backup.sh
echo "$BACKUP_SCHEDULE /app/duplicacy-autobackup.sh backup" > /var/spool/cron/crontabs/root
/app/duplicacy-autobackup.sh init

if [[ $BACKUP_IMMEDIATLY == "yes" ]]; then
echo "Running a backup right now"
/app/duplicacy-autobackup.sh backup
fi

crond -l 8 -f
3 changes: 2 additions & 1 deletion test.sh → tests/test-immediate-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ docker run -d --name duplicacy-autobackup \
-v $temp_dir/data:/data \
-e BACKUP_NAME=$BACKUP_NAME \
-e BACKUP_LOCATION="$BACKUP_LOCATION" \
-e BACKUP_SCHEDULE='* * * * *' \
-e BACKUP_SCHEDULE='0 2 * * *' \
-e BACKUP_IMMEDIATLY='yes' \
-e BACKUP_ENCRYPTION_KEY="$PASSPHRASE" \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_KEY=$AWS_SECRET_ACCESS_KEY \
Expand Down

0 comments on commit 260af7a

Please sign in to comment.