diff --git a/.travis.yml b/.travis.yml index 515a2ee..23e496d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/Dockerfile b/Dockerfile index fafe76f..eacede3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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='' \ diff --git a/README.md b/README.md index 113ab0f..6e7e705 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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). diff --git a/backup.sh b/duplicacy-autobackup.sh similarity index 80% rename from backup.sh rename to duplicacy-autobackup.sh index 9b1ce44..e8e406d 100644 --- a/backup.sh +++ b/duplicacy-autobackup.sh @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 92c8c54..37a8ca2 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 \ No newline at end of file diff --git a/test.sh b/tests/test-immediate-backup.sh similarity index 96% rename from test.sh rename to tests/test-immediate-backup.sh index e8becd4..4edc568 100755 --- a/test.sh +++ b/tests/test-immediate-backup.sh @@ -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 \