From e56e1a983a052e96c10ecabfb0cf71dfa371b093 Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Fri, 9 Mar 2018 17:29:41 -0800 Subject: [PATCH] Add ability to auto restore --- Readme.md | 1 + entrypoint.sh | 6 ++++++ itest.sh | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 2fdd002..e9e433f 100644 --- a/Readme.md +++ b/Readme.md @@ -21,6 +21,7 @@ Mount any directories you'd like to back up as a volume and run |OPT_ARGUMENTS| |Any additional arguments to provide to the duplicity backup command. These can also be provided as additional arguments via the command line| |PASSPHRASE|Correct.Horse.Battery.Staple|Passphrase to use for GPG| |PATH_TO_BACKUP|/data|The path to the directory you wish to backup. If you want to backup multiple, see the [tip below](#backing-up-more-than-one-source-directory)| +|RESTORE_ON_EMPTY_START| |Set this to "true" and if the `$PATH_TO_BACKUP` is empty, it will restore the latest backup. This can be used for auto recovery from lost data| |SKIP_ON_START| |Skips backup on start if set to "true"| |VERIFY_CRON_SCHEDULE| |If you want to verify your backups on a schedule, provide it here| diff --git a/entrypoint.sh b/entrypoint.sh index 9b872f1..1480490 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,6 +16,12 @@ if [ -e "$GPG_KEY_ID" ]; then export OPT_ARGUMENTS="$OPT_ARGUMENTS --encrypt-sign-key=\"$GPG_KEY_ID\"" fi +# If set to restore on start, restore if the data volume is empty +if [ "$RESTORE_ON_EMPTY_START" == "true" -a -z "$(ls -A $PATH_TO_BACKUP)" ]; then + /restore.sh +fi + +# Unless explicitly skipping, take a backup on startup if [ "$SKIP_ON_START" != "true" ]; then /backup.sh fi diff --git a/itest.sh b/itest.sh index f9b5303..dbe2248 100755 --- a/itest.sh +++ b/itest.sh @@ -19,13 +19,28 @@ echo "Verify backup..." echo "Delete test data..." rm -fr /data/* +echo "Verify deleted..." +test -f /data/test.txt && exit 1 || echo "Gone" + echo "Restore backup..." /restore.sh echo "Verify backup..." /verify.sh -echo "Verify incorrect passphrase fails..." +echo "Delete test data again..." +rm -fr /data/* + +echo "Verify deleted..." +test -f /data/test.txt && exit 1 || echo "Gone" + +echo "Simulate a restart with RESTORE_ON_EMPTY_START..." +RESTORE_ON_EMPTY_START=true /entrypoint.sh + +echo "Verify restore happened..." +test -f /data/test.txt + +echo "Verify restore with incorrect passphrase fails..." export PASSPHRASE=Incorrect.Mule.Solar.Paperclip echo "Fail to restore backup..."