Backup hosts, organised as clusters by domain.
The backups appear as images of the client hosts at various times (snapshots).
rsnapshot pulls files via rsync, utilising its efficiencies:
only files that have changed;
compression;
storing using hard links to existing (unchanged) stored files
to avoid multiple copies of identical (same inode) files within the backup.
2022-08-01 Ubuntu 21.10-22.04
Main characteristics of this domain-oriented implementation:
Each domain has its own configuration file; they are backed up
independently: /etc/rsnapshot/domain/rsnapshot.conf.
Each domain has its own backup media; they are mounted or symlinked
appropriately: /srv/backups/domain/.
There are daily (for a week), weekly (for a month) and monthly
(retain three) backups.
Backups are scheduled via cron.
Installation
graham:~sudo apt updategraham:~sudo apt install rsnapshotgraham:~sudo mv /etc/rsnapshot.conf /etc/rsnapshot.conf-dist # save as template
graham:~sudo mkdir /etc/rsnapshot # container for per-domain configs
graham:~sudo mkdir /srv/backup # container for per-domain backups
graham:~sudo chown root:adm /srv/backupgraham:~sudo chmod 750 /srv/backupgraham:~sudo mkdir /run/rsnapshot # container for per-domain run files
graham:~sudo mkdir /var/log/rsnapshot # container for per-domain logs
graham:~sudo chown root:adm /var/log/rsnapshotgraham:~sudo vi /etc/tmpfiles.d/rsnapshot.conf
Add domain for backing up
This example adds domain geddy.au for backing up,
but no hosts within it as yet.
graham:~sudo mkdir /etc/rsnapshot/geddy.augraham:~cd /etc/rsnapshot/geddy.augraham:/etc/rsnapshot/geddy.ausudo cp /etc/rsnapshot.conf-dist rsnapshot.confgraham:/etc/rsnapshot/geddy.ausudo vi rsnapshot.conf
Then delete file content after line
'### BACKUP POINTS / SCRIPTS ###'.
Arrange for this domain's backup media to appear as this directory.
Simplest case is an external hard drive mounted onto
/srv/backup and allow all domains to appear as subdirs.
graham:/etc/rsnapshot/geddy.ausudo crontab -e
Adjust the backup schedule to requirements,
but maintain the temporal sequencing i.e. if a monthly runs, it must be
just before the weekly; if a weekly runs, it must be just before the daily.
Add client host to backed-up domain
The backup server must have keyed passwordless ssh
access by root to client hosts's root account.
Briefly, this usually means:
A copy of backup server's /root/.ssh/id_rsa.pub file must be
appended to the client hosts's /root/.ssh/authorized_keys
file;
Parameter PermitRootLogin must be yes in the
client hosts's /etc/ssh/sshd_config file.
The example is based upon:
Domain name
geddy.au
Host
s0 – web server
Host
s1 – mail server
graham:~cd /etc/rsnapshot/geddy.augraham:/etc/rsnapshot/geddy.ausudo vi rsnapshot.conf
This is deliberately not a full system backup,
only of our data.
The presumption is that everything else is re-installed or ephemeral.
Adjust the inclusions (and exclusions) as required.
In this example, the only subtree needing pruning for backup is
/var, and the exclusions are listed in the specified files.
The backup directive backs up binary copies of the files.
This is not always appropriate e.g. an SQL database.
The example shows backup_script calling a locally
implemented script (see further below) that creates a suitable dump
that is then configured to be placed alongside the
backup tree.
graham:/etc/rsnapshot/geddy.ausudo vi s0-var.exclgraham:/etc/rsnapshot/geddy.ausudo cp s0-var.excl s1-var.excl
In this case, s1's exclusions are identical to s0's.
graham:/etc/rsnapshot/geddy.ausudo vi /usr/local/sbin/pg_dumpallgraham:/etc/rsnapshot/geddy.ausudo chmod 554 /usr/local/sbin/pg_dumpallgraham:/etc/rsnapshot/geddy.ausudo ln -s /usr/local/sbin/pg_dumpall /usr/local/sbin/pg_dumpall-s1.geddy.au
Creates template postgres database dump script.
rsnapshotbackup_script takes no arguments so the
remote hostname is embedded in filename (after trailing hyphen).
Use template to create dumpall script for s1.geddy.au
by symlinking with appropriate filename.
This requires passwordless ssh access from root@localhost
to postgres@s1.geddy.au (not shown here).
File restoration
Obviously restoration is highly contextual.
The following path is highly instructive on backup image locations:
/srv/backup/geddy.au/daily.0/s0/etc/hosts
– the most recent daily backup of s0.geddy.au's
/etc/hosts file.