Docker containers back-up with shell scripts

Docker containers back-up with some small schell scripts twice per month

We’ll be making 2 small shell scripts to backup our containers and insert them in crontab.
Theese scripts are for two containers but you can extend them as you please.

I have two containers nginx/php-fpm and mariadb. We’ll put our shell script inside /home

First is named and second

(to see active containers)

docker ps to see active containers
docker ps to see active containers

Here we have 3 containers mariadb and nginx-php-fpm with ids b7b7ad5f1314 and f541404f564f and with names tot9_mariadb and tot9_nginx-php-fpm
Now we start our shell scripts:

after we opened the file we place:

ctrl+x and yes to save.
Where b7b7ad5f1314 is container id, we can also use container name (tot9_mariadb) and maria/installed:v1 is the name that we give to container image.

commmariash shell script
commmariash shell script

we do the same with

Now we need to make both our scripts executables

Now we open our cronjobs:

crontab -e  to edit cronjobs
crontab -e to edit cronjobs

If asked you must choose and editor (I went with nano, most common options are nano and vim).
write this in there:

where /dev/null 2>&1 is for null output (so you don’t receive email if you have it for root). 15 and 20 are minutes, 10 is the hour and 1,15 are the two days * is day of week and * is month. These two scripts will run on 1th and 15th every month

You can also check if cron service is active:

Last modified: August 28, 2017