From cd74483e94bdd20df7a4fe0be815358833e6dce2 Mon Sep 17 00:00:00 2001 From: rgmcewan Date: Sat, 26 Oct 2024 14:41:32 +1000 Subject: [PATCH] new script with confirmation email --- docker2-backup-email.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 docker2-backup-email.sh diff --git a/docker2-backup-email.sh b/docker2-backup-email.sh new file mode 100644 index 0000000..863fd59 --- /dev/null +++ b/docker2-backup-email.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Get today's date for our backup filename +backupDate=$(date +'%F') + +echo "Stopping all containers..." | tee docker-$backupDate.log +docker stop $(docker ps -a -q) >> docker-$backupDate.log 2>&1 + +# Enter backup directory +cd /home/debian/dockerbackup || exit + +echo "Creating a tar archive of your docker parent folder..." | tee -a docker-$backupDate.log +tar -czvf $backupDate-backup-docker2.tar.gz /docker >> docker-$backupDate.log 2>&1 + +# Start ALL containers +echo "Starting all containers..." | tee -a docker-$backupDate.log +docker start $(docker ps -a -q) >> docker-$backupDate.log 2>&1 + +echo "Uploading backup file to BackBlaze..." | tee -a docker-$backupDate.log +rclone copy $backupDate-backup-docker2.tar.gz b2:rgm-docker2 --progress >> docker-$backupDate.log 2>&1 + +# remove the tar file from the main home folder after it's copied +echo "Removing local backup cache..." | tee -a docker-$backupDate.log +rm -rf $backupDate-backup-docker2.tar.gz >> docker-$backupDate.log 2>&1 + +# Email log to an email address +sendmail -s "Docker Backup Completed" rgmcewan@outlook.com < docker-$backupDate.log + +echo "Docker Backup Completed Successfully!" | tee -a docker-$backupDate.log \ No newline at end of file