How MOOSE Do Backups

We configure Borg Backup out of the box for MOOSE-managed servers. The benefits of this system are:

  • deduplication
  • compression
  • encryption
  • storage off-site (hosts in Manchester have backups in Geneva, and vice-versa)
  • multiple backups with a pruning schedule

To make backups of MySQL databases, we also use automysqlbackup which stores a gzipped mysqldump file for each database, every day, in /var/lib/automysqlbackup.

By default borg is set to run every day at the server's daily cron job time:

  • backup all your configuration files in /etc and retain: 28 days and 12 months
  • backup all your sites and user data in /home and retain: 7 days, 4 weeks, and 6 months
  • backup all email account data in /srv/mail and retain: 7 days, 2 weeks, and 2 months
  • backup MySQL database backups kept in /var/lib/automysqlbackup and retain: 3 days, 2 weeks, and 1 month
  • backup calendar data stored in /srv/radicale and retain: 7 days, 2 weeks, and 2 months

Browsing Backups

  • . /etc/faelix/moose/borgbackup to get the configuration loaded
  • export BORG_PASSPHRASE so you don't need to type the passphrase
  • borg list $REPOSITORY to show all the backups

For example:

etc-2017-02-17                       Fri, 2017-02-17 04:11:06
home-2017-02-17                      Fri, 2017-02-17 04:11:10
mail-2017-02-17                      Fri, 2017-02-17 04:11:14
radicale-2017-02-17                  Fri, 2017-02-17 04:11:17
mysql-2017-02-17                     Fri, 2017-02-17 04:11:21

Here we have backups of /etc, /home, /srv/mail, /srv/radicale and /var/lib/automysqlbackup all taken on 2017-02-17 (17th February 2017).

To show information about a specific backup archive, say mysql-2017-02-17:

  • . /etc/faelix/moose/borgbackup to get the configuration loaded
  • export BORG_PASSPHRASE so you don't need to type the passphrase
  • borg info $REPOSITORY::mysql-2017-02-17 will show you the information

In our example:

Name: mysql-2017-02-17
Fingerprint: 3c01cef01f61b229325a76f58de050ef8b381a14abe2ed4846feb55aec97e243
Hostname: moose.faelix.net
Username: root
Time (start): Fri, 2017-02-17 04:11:21
Time (end):   Fri, 2017-02-17 04:11:21
Command line: /usr/local/bin/borg create --compression none -v --stats borg@borg0.g.faelix.net:/home/borg/moose.faelix.net::mysql-{now:%Y-%m-%d} /var/lib/automysqlbackup/latest
Number of files: 6

                       Original size      Compressed size    Deduplicated size
This archive:                7.40 kB              7.74 kB              7.74 kB
All archives:              192.25 MB             90.09 MB             11.01 MB

                       Unique chunks         Total chunks
Chunk index:                    3348                36053

This shows us when the backup was created, what it is a backup of, and how large it is (compressed, and deduplicated).

Making an Extra Backup

Sometimes you want to take an extra backup, either just before or just after a large change. We've made this easy with just one command:

  • moose.backup before-upgrade will create backups of everything, giving them names ending YYYY-MM-DD-before-upgrade (where YYYY-MM-DD is the date)

You might want to do a backup after your changes as well, just to give extra peace of mind.

Restoring Data from Backup

  • . /etc/faelix/moose/borgbackup to get the configuration loaded
  • export BORG_PASSPHRASE so you don't need to type the passphrase
  • borg mount $REPOSITORY /mnt to mount the backups so you can copy files out of previous versions
  • umount /mnt when you're done