Browse Source

Add restore script and restore test

itest
ViViDboarder 2 years ago
parent
commit
b3ff6b6cce
8 changed files with 47 additions and 12 deletions
  1. 2
    1
      Dockerfile.raspbian
  2. 2
    1
      Dockerfile.ubuntu
  3. 1
    1
      Readme.md
  4. 1
    5
      backup.sh
  5. 5
    0
      entrypoint.sh
  6. 10
    0
      restore.sh
  7. 19
    3
      test.sh
  8. 7
    1
      verify.sh

+ 2
- 1
Dockerfile.raspbian 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" ]

+ 2
- 1
Dockerfile.ubuntu 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" ]

+ 1
- 1
Readme.md 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

+ 1
- 5
backup.sh 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

+ 5
- 0
entrypoint.sh 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
- 0
restore.sh 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


+ 19
- 3
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

+ 7
- 1
verify.sh 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

Loading…
Cancel
Save