Add automated db backups as part of Trellis?

I just did my first Ansible script for making automated backups of production server’s db. Here is my ansible task:

---
- name: Create directory for backups
  file:
    path: "/db-backups"
    state: directory
​
- name: Set weekly database backups
  cron:
    name: "Weekly database backup"
    job: "{{ site_path }}/prod-db-backup.sh"
    minute: 0
    hour: 1
    weekday: 1

And here is prod-db-backup.sh

cd /srv/www/mysite.com/current
wp db export /db-backups/mysite-`date +%d-%m-%Y`.sql --allow-root

This way crontab makes every monday at 1 AM mysql dump of the whole production database.

Have you guys though of making this kind of behaviour part Trellis? I am sure that many people would like to have this feature since backups are very important. Guys at Digital Ocean said you shouln’t trust their backups 100% when dealing with databases. They recommend to do your sqldump files also like I did :slight_smile:

2 Likes

I have a work-in-progress role that sets this up without an sh script. Check it out here. The library I’m using to set up the jobs has some bugs noted in that thread.

2 Likes