Linux: Backup with rsync#
The script below is a simple backup solution. I stash external disks on various locations where I work. Whenever I have access I plug them in, they get mounted and with teh script I mirror my home directory. Please note that the disks are encrypted using LUKS.
1#!/bin/bash
2
3# Set your backup mediums name:
4
5BackupMediumName=BuBackup
6
7# Where ist the backup medium mounted?
8
9if [[ -d /media/$(logname)/$BackupMediumName ]]
10then
11 echo "Found backup medium under /media/$(logname)/$BackupMediumName ...";
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 PathBackup=/run/media/$(logname)/$BackupMediumName/$(hostname)$HOME;
17else
18 echo "CRITICAL ERROR: Couldn't detect backup medium!";
19 exit 1;
20fi
21
22echo "rsync -avX --delete --exclude={".cache"} $HOME/ $PathBackup";
23rsync -avX --delete --exclude={".cache"} $HOME/ $PathBackup;