Backup Strategy#
I have a 3 thier backup strategy.
On the first thier my work is either synced using a personal cloud (most general documents) or to various git repositories on a self hosted gitea server (text based like Sphinx projects, code etc.).
The second thier consists of regular sync of my home directory to various encrypted external hard drives stashed in different locations, seeh Linux: Backup with rsync below.
The third thier consists of syncs of all my data on cold storage mediums.
Linux: Backup with rsync#
The script below is a simple backup solution. I use external hard disks with a LUKS encrypted partition and stash them in various locations. Simply plug them in, decrypt and mount them and ran the rsync script to mirror the home directory. If you use a BTRFSvolume, you can use snapshots to freeze the state of the former backup to be able to jump back and forth in time in case you are searching for a lost file.
1#!/bin/bash
2
3# Set your backup mediums name:
4BackupMediumName=BuBackup
5
6# Check if backup medium is mounted under /media or /run/media and set
7# $PathMedium and $PathBackup accordingly.
8if [[ -d /media/$(logname)/$BackupMediumName ]]
9then
10 echo "Found backup medium under /media/$(logname)/$BackupMediumName ...";
11 PathMedium=/media/$(logname)/$BackupMediumName/$(hostname)
12 PathBackup=/media/$(logname)/$BackupMediumName/$(hostname)$HOME;
13elif [[ -d /run/media/$(logname)/$BackupMediumName ]]
14then
15 echo "Found backup medium under /run/media/$(logname)/$BackupMediumName ...";
16 PathMedium=/run/media/$(logname)/$BackupMediumName/$(hostname);
17 PathBackup=/run/media/$(logname)/$BackupMediumName/$(hostname)$HOME;
18else
19 echo "CRITICAL ERROR: Couldn't detect backup medium!";
20 exit 1;
21fi
22
23# If $PathMedium is a BRTFS subvolume, create a snapshot before syncing.
24if [ `stat --format=%i $PathMedium` -eq 256 ];
25then
26 echo "$PathMedium is a BRTFS subvolume, creating read-only subvolume $PathMedium-`date --iso-8601=seconds`-ro"
27 btrfs subvolume snapshot -r $PathMedium $PathMedium-`date --iso-8601=seconds`-ro
28fi
29
30echo "rsync -avX --delete --exclude={".cache"} $HOME/ $PathBackup";
31rsync -avX --delete --exclude={".cache"} $HOME/ $PathBackup;
32
33
34# For specific workstations you might want to do some extra stuff ..
35if [ $(hostname) == 'SomeSpecialWorkstation' ]
36then
37 echo "Do something special .. ";
38 # put extra stuff in here
39else
40 echo "This is not SomeSpecialWorkstation, doing nothing special ..";
41fi