Open phit42 opened 1 year ago
Thanks for this. I'm using it and it works great
i found this project useful, as my watchtower containers sometimes fail to create containers after the update, so i have to backup the compose files to redeploy afterwards..
if you wanna use the python file itself, this is what i use for my daily cron job the files are backed up into the same folder where the python file is, you can change this with:
and the output captures all containers but each container is grouped individually into (in order):
and at the end, it generates a timelog of when the cron job completes
#!/bin/bash
autocomposedir="/home/backuper/docker-backup"
yamlbackupdir="yaml-backups"
IFS=$'\n'
containers=$(docker ps -a --format "{{.ID}} {{.Names}}" | sort -k 2)
dockerupcounter=1
MAX=$(docker info --format "{{json .Containers}}")
SECONDS=0
echo ================================
echo "Started container config backup on: $(date +%d-%b-%Y\ %H:%M:%S\ %p\ %Z)"
for container in $containers
do
IFS=$' '
containerID=($container)
echo "$dockerupcounter/$MAX: $container"
datefolder=$(date +%d-%m-%Y)
mkdir -p "$autocomposedir/$yamlbackupdir/$datefolder/${containerID[1]}/${containerID[0]}"
sudo python3 $autocomposedir/autocompose.py ${containerID[0]} > "$autocomposedir/$yamlbackupdir/$datefolder/${containerID[1]}/${containerID[0]}/$(date +%H-%M-%S\ %p\ %Z).yaml"
dockerupcounter=$(expr $dockerupcounter + 1)
done
echo "Backup completed : $(date +%d-%b-%Y\ %H:%M:%S\ %p\ %Z)" >> $autocomposedir/$yamlbackupdir/backups.log
echo "Backup time took : $SECONDS seconds"
IFS=$' \t\n'
if you want a version that you manually start, and has a progress bar with rclone backup: check out my other fuller fledged file at: backup-container-configs.sh , just place the file where the python autocompose file is
Just my 2cents on a way to execute docker-autocompose: