misc

Backing up from a MariaDB database that is in a Docker container

October 29, 2019 mariadb, backup

Backing up MariaDB database

For this blog I am using a docker instance that is hosing a MariaDB database. I needed a way to automatically backup the database and upload it to another server.

Do note that I would recommend using a full path for the file name. IE: /home/pi/backups/blog-backup-$(date '+%Y-%m-%d).sql. We will need to assign executable permissions on the script that we just created. This can be achieved by the following command.


chmod +x ./backupScript.sh

Next step would be adding it to Crontab to run at a schedule time. The following command will launch the crontab file.


crontab -e

Append the following line to the crontab to run the script at midnight everyday.

0 0 * * * [FULL PATH TO SCRIPT] >> /home/pi/cronlog.log 2>&1

I like to redirect the output of a script into a file and perform confirmations on that file. The >> /home/pi/cronlog.log 2>&1 will redirect the output to the file cronlog.log. If everything is okay, your database will be uploaded to Google Drive daily at midnight. Note that if your database has confidential data, I would highly recommend against using this method.