Add restore script and restore test

This commit is contained in:
ViViDboarder 2017-06-28 23:28:48 -07:00
parent 7dfaef9365
commit b3ff6b6cce
8 changed files with 47 additions and 12 deletions

View File

@ -22,8 +22,9 @@ ENV PASSPHRASE="Correct.Horse.Battery.Staple"
ENV CRON_SCHEDULE="" ENV CRON_SCHEDULE=""
ENV VERIFY_CRON_SCHEDULE="" ENV VERIFY_CRON_SCHEDULE=""
ADD entrypoint.sh /
ADD backup.sh / ADD backup.sh /
ADD entrypoint.sh /
ADD restore.sh /
ADD verify.sh / ADD verify.sh /
ENTRYPOINT [ "/entrypoint.sh" ] ENTRYPOINT [ "/entrypoint.sh" ]

View File

@ -21,8 +21,9 @@ ENV PASSPHRASE="Correct.Horse.Battery.Staple"
ENV CRON_SCHEDULE="" ENV CRON_SCHEDULE=""
ENV VERIFY_CRON_SCHEDULE="" ENV VERIFY_CRON_SCHEDULE=""
ADD entrypoint.sh /
ADD backup.sh / ADD backup.sh /
ADD entrypoint.sh /
ADD restore.sh /
ADD verify.sh / ADD verify.sh /
ENTRYPOINT [ "/entrypoint.sh" ] ENTRYPOINT [ "/entrypoint.sh" ]

View File

@ -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 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 ### 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 - [ ] Automatic restoration if there is no source data

View File

@ -1,11 +1,6 @@
#! /bin/bash #! /bin/bash
set -e 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 \ duplicity \
--allow-source-mismatch \ --allow-source-mismatch \
--asynchronous-upload \ --asynchronous-upload \
@ -18,5 +13,6 @@ duplicity \
if [ -n "$CLEANUP_COMMAND" ]; then if [ -n "$CLEANUP_COMMAND" ]; then
duplicity $CLEANUP_COMMAND \ duplicity $CLEANUP_COMMAND \
--log-file /root/duplicity.log \ --log-file /root/duplicity.log \
--name $BACKUP_NAME \
$BACKUP_DEST $BACKUP_DEST
fi fi

View File

@ -7,6 +7,11 @@ if [ "$1" == "bash" ]; then
exit 0 exit 0
fi 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 if [ "$SKIP_ON_START" != "true" ]; then
/backup.sh /backup.sh
fi fi

10
restore.sh Executable file
View File

@ -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

22
test.sh
View File

@ -6,10 +6,26 @@ tag=$2
full_image="${image_name}:${tag}" full_image="${image_name}:${tag}"
container_name="${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 # Create backup container
sleep 2 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" 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 docker exec $container_name /backup.sh
# Verify the backup
echo "Verify backup..."
docker exec $container_name /verify.sh 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 docker rm $container_name

View File

@ -1,4 +1,10 @@
#! /bin/bash #! /bin/bash
set -e 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