From b3ff6b6ccef10da3e2dcc9a7b305c6e1c5966128 Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Wed, 28 Jun 2017 23:28:48 -0700 Subject: [PATCH] Add restore script and restore test --- Dockerfile.raspbian | 3 ++- Dockerfile.ubuntu | 3 ++- Readme.md | 2 +- backup.sh | 6 +----- entrypoint.sh | 5 +++++ restore.sh | 10 ++++++++++ test.sh | 22 +++++++++++++++++++--- verify.sh | 8 +++++++- 8 files changed, 47 insertions(+), 12 deletions(-) create mode 100755 restore.sh diff --git a/Dockerfile.raspbian b/Dockerfile.raspbian index a2c6e5e..e416c7c 100644 --- a/Dockerfile.raspbian +++ b/Dockerfile.raspbian @@ -22,8 +22,9 @@ ENV PASSPHRASE="Correct.Horse.Battery.Staple" ENV CRON_SCHEDULE="" ENV VERIFY_CRON_SCHEDULE="" -ADD entrypoint.sh / ADD backup.sh / +ADD entrypoint.sh / +ADD restore.sh / ADD verify.sh / ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu index f3a0eca..649d031 100644 --- a/Dockerfile.ubuntu +++ b/Dockerfile.ubuntu @@ -21,8 +21,9 @@ ENV PASSPHRASE="Correct.Horse.Battery.Staple" ENV CRON_SCHEDULE="" ENV VERIFY_CRON_SCHEDULE="" -ADD entrypoint.sh / ADD backup.sh / +ADD entrypoint.sh / +ADD restore.sh / ADD verify.sh / ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/Readme.md b/Readme.md index 1036446..8dfa5e1 100644 --- a/Readme.md +++ b/Readme.md @@ -39,5 +39,5 @@ PATH_TO_BACKUP="/" Mount all volumes from your existing container with `--volumes-from` and then back up by providing the paths to those volumes. If there are more than one volumes, you'll want to use the above tip for mulitple backup sources ### To Do - - [ ] Some easy way to trigger restoration + - [x] Some easy way to trigger restoration (can now exec /restore.sh) - [ ] Automatic restoration if there is no source data diff --git a/backup.sh b/backup.sh index bf7c864..16671c7 100755 --- a/backup.sh +++ b/backup.sh @@ -1,11 +1,6 @@ #! /bin/bash set -e -# If key id is provied add arg -if [ -e "$GPG_KEY_ID" ]; then - OPT_ARGUMENTS="$OPT_ARGUMENTS --encrypt-sign-key=\"$GPG_KEY_ID\"" -fi - duplicity \ --allow-source-mismatch \ --asynchronous-upload \ @@ -18,5 +13,6 @@ duplicity \ if [ -n "$CLEANUP_COMMAND" ]; then duplicity $CLEANUP_COMMAND \ --log-file /root/duplicity.log \ + --name $BACKUP_NAME \ $BACKUP_DEST fi diff --git a/entrypoint.sh b/entrypoint.sh index 144736d..0fb4674 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,6 +7,11 @@ if [ "$1" == "bash" ]; then exit 0 fi +# If key id is provied add arg +if [ -e "$GPG_KEY_ID" ]; then + OPT_ARGUMENTS="$OPT_ARGUMENTS --encrypt-sign-key=\"$GPG_KEY_ID\"" +fi + if [ "$SKIP_ON_START" != "true" ]; then /backup.sh fi diff --git a/restore.sh b/restore.sh new file mode 100755 index 0000000..a2fe599 --- /dev/null +++ b/restore.sh @@ -0,0 +1,10 @@ +#! /bin/bash +set -e + +duplicity restore \ + --log-file /root/duplicity.log \ + --name $BACKUP_NAME \ + $OPT_ARGUMENTS \ + $BACKUP_DEST \ + $PATH_TO_BACKUP + diff --git a/test.sh b/test.sh index af8ab5a..15b0fef 100755 --- a/test.sh +++ b/test.sh @@ -6,10 +6,26 @@ tag=$2 full_image="${image_name}:${tag}" container_name="${image_name}-${tag}" -docker run -d -e CRON_SCHEDULE="0 0 12 1 1 ? *" -e SKIP_ON_START=true --name $container_name $full_image -sleep 2 +# Create backup container +docker run -d -e SKIP_ON_START=true --name ${container_name} $full_image bash -c "/bin/sleep 20" +# Create some test data docker exec $container_name sh -c "mkdir -p /data && echo Test > /data/test.txt" +# Backup data +echo "Making backup..." docker exec $container_name /backup.sh +# Verify the backup +echo "Verify backup..." docker exec $container_name /verify.sh -docker stop $container_name +# Remove test file +echo "Clear data..." +docker exec $container_name sh -c "rm /data/*" +# Restore the backup +echo "Restore backup..." +docker exec $container_name /restore.sh +# Verify the backup +echo "Verify backup..." +docker exec $container_name /verify.sh +# Stop the container +docker kill $container_name +# Remove the container docker rm $container_name diff --git a/verify.sh b/verify.sh index 49f73ce..f11ff35 100755 --- a/verify.sh +++ b/verify.sh @@ -1,4 +1,10 @@ #! /bin/bash set -e -duplicity verify $BACKUP_DEST $PATH_TO_BACKUP +duplicity verify \ + --compare-data \ + --log-file /root/duplicity.log \ + --name $BACKUP_NAME \ + $OPT_ARGUMENTS \ + $BACKUP_DEST \ + $PATH_TO_BACKUP