Browse Source

Add restore script and restore test

itest
ViViDboarder 1 year 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"
22 22
 ENV CRON_SCHEDULE=""
23 23
 ENV VERIFY_CRON_SCHEDULE=""
24 24
 
25
-ADD entrypoint.sh /
26 25
 ADD backup.sh /
26
+ADD entrypoint.sh /
27
+ADD restore.sh /
27 28
 ADD verify.sh /
28 29
 
29 30
 ENTRYPOINT [ "/entrypoint.sh" ]

+ 2
- 1
Dockerfile.ubuntu View File

@@ -21,8 +21,9 @@ ENV PASSPHRASE="Correct.Horse.Battery.Staple"
21 21
 ENV CRON_SCHEDULE=""
22 22
 ENV VERIFY_CRON_SCHEDULE=""
23 23
 
24
-ADD entrypoint.sh /
25 24
 ADD backup.sh /
25
+ADD entrypoint.sh /
26
+ADD restore.sh /
26 27
 ADD verify.sh /
27 28
 
28 29
 ENTRYPOINT [ "/entrypoint.sh" ]

+ 1
- 1
Readme.md View File

@@ -39,5 +39,5 @@ PATH_TO_BACKUP="/"
39 39
 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
40 40
 
41 41
 ### To Do
42
- - [ ] Some easy way to trigger restoration
42
+ - [x] Some easy way to trigger restoration (can now exec /restore.sh)
43 43
  - [ ] Automatic restoration if there is no source data

+ 1
- 5
backup.sh View File

@@ -1,11 +1,6 @@
1 1
 #! /bin/bash
2 2
 set -e
3 3
 
4
-# If key id is provied add arg
5
-if [ -e "$GPG_KEY_ID" ]; then
6
-    OPT_ARGUMENTS="$OPT_ARGUMENTS --encrypt-sign-key=\"$GPG_KEY_ID\""
7
-fi
8
-
9 4
 duplicity \
10 5
     --allow-source-mismatch \
11 6
     --asynchronous-upload \
@@ -18,5 +13,6 @@ duplicity \
18 13
 if [ -n "$CLEANUP_COMMAND" ]; then
19 14
     duplicity $CLEANUP_COMMAND \
20 15
         --log-file /root/duplicity.log \
16
+        --name $BACKUP_NAME \
21 17
         $BACKUP_DEST
22 18
 fi

+ 5
- 0
entrypoint.sh View File

@@ -7,6 +7,11 @@ if [ "$1" == "bash" ]; then
7 7
     exit 0
8 8
 fi
9 9
 
10
+# If key id is provied add arg
11
+if [ -e "$GPG_KEY_ID" ]; then
12
+    OPT_ARGUMENTS="$OPT_ARGUMENTS --encrypt-sign-key=\"$GPG_KEY_ID\""
13
+fi
14
+
10 15
 if [ "$SKIP_ON_START" != "true" ]; then
11 16
     /backup.sh
12 17
 fi

+ 10
- 0
restore.sh View File

@@ -0,0 +1,10 @@
1
+#! /bin/bash
2
+set -e
3
+
4
+duplicity restore \
5
+    --log-file /root/duplicity.log \
6
+    --name $BACKUP_NAME \
7
+    $OPT_ARGUMENTS \
8
+    $BACKUP_DEST \
9
+    $PATH_TO_BACKUP
10
+

+ 19
- 3
test.sh View File

@@ -6,10 +6,26 @@ tag=$2
6 6
 full_image="${image_name}:${tag}"
7 7
 container_name="${image_name}-${tag}"
8 8
 
9
-docker run -d -e CRON_SCHEDULE="0 0 12 1 1 ? *" -e SKIP_ON_START=true --name $container_name $full_image
10
-sleep 2
9
+# Create backup container
10
+docker run -d -e SKIP_ON_START=true --name ${container_name} $full_image bash -c "/bin/sleep 20"
11
+# Create some test data
11 12
 docker exec $container_name sh -c "mkdir -p /data && echo Test > /data/test.txt"
13
+# Backup data
14
+echo "Making backup..."
12 15
 docker exec $container_name /backup.sh
16
+# Verify the backup
17
+echo "Verify backup..."
13 18
 docker exec $container_name /verify.sh
14
-docker stop $container_name
19
+# Remove test file
20
+echo "Clear data..."
21
+docker exec $container_name sh -c "rm /data/*"
22
+# Restore the backup
23
+echo "Restore backup..."
24
+docker exec $container_name /restore.sh
25
+# Verify the backup
26
+echo "Verify backup..."
27
+docker exec $container_name /verify.sh
28
+# Stop the container
29
+docker kill $container_name
30
+# Remove the container
15 31
 docker rm $container_name

+ 7
- 1
verify.sh View File

@@ -1,4 +1,10 @@
1 1
 #! /bin/bash
2 2
 set -e
3 3
 
4
-duplicity verify $BACKUP_DEST $PATH_TO_BACKUP
4
+duplicity verify \
5
+    --compare-data \
6
+    --log-file /root/duplicity.log \
7
+    --name $BACKUP_NAME \
8
+    $OPT_ARGUMENTS \
9
+    $BACKUP_DEST \
10
+    $PATH_TO_BACKUP

Loading…
Cancel
Save