From 555af6499f9cc928b5a87979e4dc4d93e23df448 Mon Sep 17 00:00:00 2001 From: "rob.mcewan" Date: Sat, 26 Oct 2024 01:40:33 +0000 Subject: [PATCH] Add docker2-backup.sh Stops all docker containers and backs up the /docker directory to BackBlaze using rclone. Rclone must be configured separately using sudo rclone config (MUST BE RUN AS SUDO) --- docker2-backup.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docker2-backup.sh diff --git a/docker2-backup.sh b/docker2-backup.sh new file mode 100644 index 0000000..1942b8e --- /dev/null +++ b/docker2-backup.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Get today's date for our backup filename +backupDate=$(date +'%F') + +# this just prints the formated date variable to the console if you want to see it. +echo $backupDate + +# move to the path where you will keep all of yoru docker configurations and data +cd /docker + +# stop ALL containers +docker stop $(docker ps -a -q) + +cd /home/debian/backup +#create a tar archive of your docker parent folder +tar --exclude='./backup/' -czvf $backupDate-backup-docker2.tar.gz /docker + +cd /docker + +#Start ALL containers +docker start $(docker ps -a -q) + +# now go back to backup directory, and copy my backup file to my NAS +cd /home/debian/backup +echo "" +echo "Backup copy is running..." + +# use secure copy to copy the tar archive to your final backup location (in my case a mounted NFS share) +rclone copy $backupDate-backup-docker2.tar.gz b2:server-backup-rgm --progress + +# remove the tar file from the main home folder after it's copied +rm -rf $backupDate-backup-docker2.tar.gz + +echo "Local backup file removed..." +echo "Docker Backup Completed Successfully!"