ive been trying to get a decent backup strategy for my docker containers going for a while now. i kept having problems due to a poor decision when i initially set up my main docker server. when i first installed that server i had not installed ubuntu server in a little while so when i saw that you could install nextcloud and docker right from the initial installer i was like cool, ill give that a shot. little did i know or perhaps i missed it, the ubuntu installer installs these as snap containers. this complicated a couple things with management of the applications and data storage in nextcloud, as well as docker container management which i didnt realize docker was a container inside a snap container until a couple years after this had been installed and in use... it just hurt my head with how that complicated the setup unnecessarily.
I had first found how horrible this setup was when i had started to try and set up some scripts to backup containers. i made a script that ran some docker pause commands, did an rsync, and then unpaused the container. it had returned errors in the script saying that docker command couldnt be found. confused, i ran
and it returned /snap/bin/docker, it was then i realized i had made a horrible decision years prior.
un-phased but delayed i continued to work on trying to get the backup script running. i replaced the command in the script i was running with the full path to the binary and set up cron to run every morning at 1am. I eventually began getting alerts that the cron job was failing with the message
docker: command not found
i ended up trying a whole lot of things over the course of a couple months and couldnt figure out why the script would run perfectly fine from a shell session but when set up in cron it just wouldnt work. eventually i finally started getting a suspicion built up that there was something with the path used in cron when executing the script. i ended up finding this bug report from 2018 that described what i was running into, and luckily one wonderful person commented that they got snap commands to work from cron by specifying the path to include the path to the snap binary in the script. this finally worked and i was able to get the following script to run without issue in cron. this is pushing all of my containers over to an rsync module(22.214.171.124::Containers_servername) where the 126.96.36.199 is the ip running on a NAS which maps to a dataset which has a snapshot run daily.
subscribe to the free tier to see the example script