Son, Father & Grandfather database backup with dynamic database list

This is a quick blog post to share with you how to do set up a son, father and grandfather database backup system on your ubuntu based server. I adapted this code from Alex Saavedra’s original post back in 2011 intending to dump everything.

This system I set up runs from /var/databases/ a directory I created just for database backups, I also created /var/databases/database.list to hold the databases to be backed up.

In my implementation I backup every day, month and year and this is transferred to a DSM backup server which then transfers the files to a google drive, so we have 3 copies.

I needed to adopt his post and have a system in which we can add as many databases as we wish (or remove them) and have them backup. As I said I am short on time so I will just share the code. You will need to create a couple of scripts in /usr/local/bin using nano or vim – here is the first (the actual backup script) I created /usr/local/bin/backupdb

I then created a script named adddb in which you may add a database to your list for backup by using the syntax ‘addb ‘

I also made a script to remove databases from the list for convenience ‘removedb ‘

Following this I finally made a script to list the databases currently being backed up ‘listdbs’

Now following that you also need to set up the cron jobs to run the scripts, the original article didn’t work for me, a bit of debugging shown that the date parameters were invalid for my version of ubuntu. I fixed the cron jobs and they are as below


Leave a Reply

Your email address will not be published. Required fields are marked *