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 VERIFY_CRON_SCHEDULE=""
ADD entrypoint.sh /
ADD backup.sh /
ADD entrypoint.sh /
ADD restore.sh /
ADD verify.sh /
ENTRYPOINT [ "/entrypoint.sh" ]

View File

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

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

View File

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

View File

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

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}"
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

View File

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