eattherich.club

Snapshots

Don't risk it. Second disk it!

what

Snapshots are simply an archive of important files. They are organized together by a $NAMESPACE usually derived from the service they follow. If stored on a second disk these may serve as valuable backups for recovering broken services.

how

Create a folder in $XDG_DATA_DIRS to house snapshot archives. Then create a snapshot system group, make it the owner and give group members write access to the directory.

mkdir -p /usr/local/share/snapshots
groupadd --system snapshot
chown root:snapshot /usr/local/share/snapshots
chmod g+w /usr/local/share/snapshots

Users wishing to create snapshots should be added to this new system group.

usermod -G snapshot -a $USER

Snapshot scripts should be created as /usr/local/bin/$NAMESPACE-snapshot.sh. They should collect their specifically important data into /tmp/snapshot/$NAMESPACE and then create a date-stamped tarball in /usr/local/share/snapshots.

tar -czvf /usr/local/share/snapshots/$(date +%F)-$NAMESPACE.tar.gz -C /tmp/snapshot/$NAMESPACE .

Snapshot implementations should be configured as a systemd.service(5)...

systemctl edit $NAMESPACE-snapshot.service:
[Unit]
Description=Snapshot $NAMESPACE 

[Service]
User=$USER
Group=snapshot
ExecStart=/usr/local/bin/$NAMESPACE-snapshot.sh

...and run regularly by a systemd.timer(5).

systemctl edit $NAMESPACE-snapshot.timer
[Unit]
Description=Regularly snapshot $NAMESPACE 

[Timer]
OnBootSec=0min
OnCalendar=*-*-*
Unit=$NAMESPACE-snapshot.service

Services

mastodon-snapshot.sh