#!/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 # stop ALL containers docker stop $(docker ps -a -q) # enter backup directory cd /home/rob/docker/backup #create a tar archive of your docker parent folder tar --exclude='./backup/' -czvf $backupDate-backup-docker1.tar.gz /home/rob/docker # dir to backup #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/rob/docker/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-docker1.tar.gz b2:rgm-docker1 --progress # remove the tar file from the main home folder after it's copied rm -rf $backupDate-backup-docker1.tar.gz echo "Local backup file removed..." echo "Docker Backup Completed Successfully!"