My Docker Volume Backup

My Docker Volume Backup 1.0

No permission to download
Written over QTS 4.4.2

Settings file - DockerVolumeBackupSettings.json
JavaScript:
{
   "Docker":{
	"Emby":"/share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/emby_config/_data/BACKUP/",
	"Portainer":"/share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/portainer/",
	"Qbittorrent":"/share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/qbit/",
	"Radarr":"/share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/radarr/_data/Backups/",
	"Sonarr":"/share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/sonarr/_data/Backups/",
	"Lidarr":"/share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/lidarr/_data/Backups/",
	"Jackett":"/share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/jackett/",
	"SmokePing_Data":"/share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/smokeping_data/",
	"SmokePing_Config":"/share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/smokeping_config/",
	"JDownloader":"/share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/jdownloader_config/",
	"NetBootXYZ_Config":"/share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/netbootxyz_config/",
	"NextCloud_config":"/share/CACHEDEV1_DATA/Container/container-station-data/lib/docker/volumes/nextcloud_config/"
},
	"BackupLocation":"/share/CACHEDEV2_DATA/DATA2/export/DockerVolumes/",
	"BackupsToKeep":"7",
	"Compression7z":"-mx=9",
	"Archiver":"/usr/local/sbin/7z"
}

You can verify JSON with jq empty DockerVolumeBackupSettings.json ; echo $?
If result if diffrent from 0 , you got wrong JSON, fix it !
GOOD RESULT:
upload_2021-5-4_16-0-33.png


BAD RESULT:
upload_2021-5-4_15-59-51.png


Script - DockerVolumeBackup.sh (do not forget to chmod +x DockerVolumeBackup.sh !)
Bash:
#!/usr/bin/env bash
#expand PATH VARIABLE .. just in case
PATH=$PATH:/usr/local/sbin/
command -v jq >/dev/null 2>&1 || { echo "I require jq but it's not installed.  Aborting." >&2; exit 1; }

#get current date in file name friendly format
cdate=$(date +%Y-%m-%d_%H-%M)

#Settings for backup
JSON="/share/CACHEDEV2_DATA/DATA2/autoruns/DockerVolumeBackupSettings.json"
# check if file exists
if [ ! -f $JSON ]; then
echo "Cannot locate file with settings data ! Aborting !" >&2;
exit 1;
fi

compression_level=$(jq -r '.Compression7z' $JSON)
archiver=$(jq -r '.Archiver' $JSON)

# set backup location
BACKUP_LOCATION=$(jq -r '.BackupLocation' $JSON)
# get all dockers to backup from JSON
DOCKERS=$(jq -r '.Docker | keys[] as $k | "\($k)"' $JSON)
# convert to bash array
array=($DOCKERS)
# loop over array and do magic
for i in ${array[@]}; do
DOCKER_NAME="$i"
DOCKER_PATH=$(jq -r ".Docker.$i" $JSON)
# build command to execute
CMD="$archiver a $compression_level $BACKUP_LOCATION$cdate"_"$DOCKER_NAME.7z $DOCKER_PATH"
echo "Executing -> "$CMD
#execute it ?
eval $CMD
done
#keep last X backups
BACKUPS_TO_KEEP=$(jq -r '.BackupsToKeep' $JSON)
echo "Keeping last $BACKUPS_TO_KEEP backups in $BACKUP_LOCATION..."
find $BACKUP_LOCATION -type f -mtime +$BACKUPS_TO_KEEP -delete

RUNTIME:
ezgif.com-gif-maker.png


Add to qnap's crontab line (example):
0 4 * * * /share/CACHEDEV2_DATA/DATA2/autoruns/DockerVolumeBackup.sh 1>/dev/null 2>&1 and do not forget to reload crontab service afterwards !

RESULT:
upload_2021-5-4_16-3-54.png
  • Like
Reactions: Silas Mariusz
Author
Usunięty użytkownik pigers
Downloads
13
Views
602
First release
Last update
Rating
5.00 star(s) 1 ratings