Whoo backups... exiting, right? No. But it has to be done. This script helps automating offsite backups and thus more likely that they actually happen.
extshot
is meant to be used as an BACKUP
program invoked by cryptshot. It will copy directories with rotating names (as the ones created by rsnapshot) to a different location using stable names. Local backup directories can be easily copied this way for long-term storage to an external disk that may be moved offsite. This helps to implement the 3-2-1 backup strategy.
-
Prepare the external disk like described in this article: https://pig-monkey.com/2012/09/cryptshot-automated-encrypted-backups-rsnapshot/.
-
Install
cryptshot
andextshot
:sudo wget https://raw.githubusercontent.com/pigmonkey/cryptshot/master/cryptshot.sh -O /usr/local/bin/cryptshot.sh sudo wget https://gist.githubusercontent.com/raw/c19f707e02a274f6371697163ee18b9f/extshot.sh -O /usr/local/bin/extshot.sh sudo chmod +x /usr/local/bin/cryptshot.sh /usr/local/bin/extshot.sh
-
Create a configuration file for
cryptshot
(the UUID-style name is just a convention for distinguishing several external disks):# /etc/cryptshot-12929c96-06a6-465e-a5c1-7ebeb58b183d.conf export UUID=12929c96-06a6-465e-a5c1-7ebeb58b183d KEYFILE=/etc/12929c96-06a6-465e-a5c1-7ebeb58b183d.key BACKUP=/usr/local/bin/extshot.sh
-
Find out the UUID of the disk (not the crypt partition) to derive the device unit name from it:
# lsblk -o NAME,TYPE,MOUNTPOINT,UUID NAME TYPE MOUNTPOINT UUID sdb disk 12929c96-06a6-465e-a5c1-7ebeb58b183d ...
Now get the device unit name with
systemd-escape -p /dev/disk/by-uuid/12929c96-06a6-465e-a5c1-7ebeb58b183d
. -
Create a systemd service to trigger
cryptshot
automatically whenever the external disk is plugged in. Use the device unit name from the previous step for theRequires
andWantedBy
directives:# /etc/systemd/system/external-disk-12929c96-06a6-465e-a5c1-7ebeb58b183d.service [Unit] Description=Execute cryptshot when external disk is plugged in Requires=dev-disk-by\x2duuid-12929c96\x2d06a6\x2d465e\x2da5c1\x2d7ebeb58b183d.device [Install] WantedBy=dev-disk-by\x2duuid-12929c96\x2d06a6\x2d465e\x2da5c1\x2d7ebeb58b183d.device [Service] ExecStart=/usr/local/bin/cryptshot.sh -c /etc/cryptshot-12929c96-06a6-465e-a5c1-7ebeb58b183d.conf -i "gamma"
The optional -i
will be passed to extshot
and used as a filter to only copy the backup directories which contain this string.
Now run a systemctl daemon-reload
and be delighted that your local rsnapshot backups are automatically copied to an encrypted disk as soon as you plug it in.