Backups with Aegis

April 18, 2020

Every now and then, I have a specific need and I write a little script to get something done on my server. Recently, I was looking into writing a new script but instead opted to write a more comprehensive program.

I recently saw that the folks at Spatie were working on a comprehensive backup solution, and I figured I should build something similar and simpler for my own use case. (This means that this package won't really receive any updates or such.)

So, Aegis was born. It is a very simple console app: you specify jobs in a YAML file, and the app will run those jobs and create an archive of a specific directory and send it to a destination of choice. All that you have to do is run Aegis periodically with a cronjob.

For my own use case, I wanted Aegis to be able to create two gzipped tarballs of projects I run on my own server. The YAML file for these jobs looks like this:

After specifying what jobs need to run, it's just a matter of setting up a cronjob. I actually wanted to make sure a database dump of nicoverbruggen.be was included, so I set up a little script, lovingly called dumpie:

Before dumpie will do any work, though, I need to set up the credentials for mysqldump, via the ~/.my.cnf file. This is better than putting plain-text password credentials in the script.

[mysqldump]
user=root
password=root

Obviously, my password for MySQL is not actually that, but you get the idea. Finally, all that was left was to set up my crontab, via crontab -e:

# Take a backup of the database with dumpie every day at midnight (0:00)
0 0 * * * /home/nico/utils/dumpie > /home/nico/dumpie.log
# Take a backup with Aegis every Sunday at 1:00
0 1 * * 0 /home/nico/aegis/aegis backup:dropbox /home/nico/aegis/jobs/backup.yaml > /home/nico/aegis.log

With this, I get a nice backup of my important websites delivered to my personal Dropbox every Sunday at 1:00. It's great to have backups like this, even though I still have server backups via my VPS provider.

This is one of those fun side projects that doesn't need to become anything bigger, but fulfills a nice purpose that makes my life a little easier.