-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup_all_external.sh
More file actions
executable file
·43 lines (34 loc) · 1.21 KB
/
backup_all_external.sh
File metadata and controls
executable file
·43 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
#check if root, if not restart with sudo
if [ $EUID != 0 ]; then
sudo "$0" "$@"
exit $?
fi
mkdir /mnt/bakdrv
mount /dev/disk/by-label/linux_backups /mnt/bakdrv
# Config
HOMEOPT="-aAP --delete"
HOMELINK="--link-dest=/mnt/bakdrv/snapshots/home/last/"
HOMESRC="/home/"
HOMESNAP="/mnt/bakdrv/snapshots/home/"
HOMELAST="/mnt/bakdrv/snapshots/home/last"
ROOTOPT="-aHAXSP --delete"
ROOTLINK="--link-dest=/mnt/bakdrv/snapshots/root/last/"
ROOTSRC="/"
ROOTSNAP="/mnt/bakdrv/snapshots/root/"
ROOTLAST="/mnt/bakdrv/snapshots/root/last"
date=`date "+%Y-%b-%d:_%T"`
# Run rsync to create snapshot
rsync $HOMEOPT --exclude={"lost+found", "mnt"} $HOMELINK $HOMESRC ${HOMESNAP}$date
# Remove symlink to previous snapshot
rm -f $HOMELAST
# Create new symlink to latest snapshot for the next backup to hardlink
ln -s ${HOMESNAP}$date $HOMELAST
# Run rsync to create snapshot
rsync $ROOTOPT --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/home/*"} $ROOTLINK $ROOTSRC ${ROOTSNAP}$date
# Remove symlink to previous snapshot
rm -f $ROOTLAST
# Create new symlink to latest snapshot for the next backup to hardlink
ln -s ${ROOTSNAP}$date $ROOTLAST
umount /mnt/bakdrv
rm -r /mnt/bakdrv