blob: a01a78e09b9b570d0743515e5b6f2cd7ef7f0199 (
plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#!/bin/bash
# vim:ft=sh
# New line separated list of all directories to backup
read -d '' DIRS <<-"_EOF_"
/etc
/home
/home_hdd
_EOF_
# Directory where backup will be stored
BACKUP=backup
# Directory where backup will be mounted
MBACKUP=/media/backup-hdd
# UUID of disk
UUID=21e0c8dd-77cc-44f1-b2bd-bb238d142e7f
####################################################################
# Check if running as root
if [ `id -u` -ne "0" ]; then
echo Please run this as root.
exit 1
fi
# Mount backup disk if available
PART=$(lsblk -fpl | grep "$UUID" | awk '{print $1}')
if [ -z "$PART" ]; then
echo Disk not detected. Exiting
exit -1
fi
MPATH=$(lsblk -lp | grep "$PART" | awk '{print$7}')
if [ -n "$MPATH" ]; then
while read -r DIR; do
if echo "$MPATH" | grep -q "$DIR"; then
echo Disk seems to be mounted to one of backuped paths. Please unmount it first.
exit -2
fi
done <<< "$DIRS"
echo Disk already mounted to $MPATH. Continuing with that.
else
MPATH=$MBACKUP
mkdir -p "$MPATH"
mount "$PART" "$MPATH"
fi
mkdir -p "$MPATH/$BACKUP"
while read -r DIR; do
echo Backing up: $DIR
rdiff-backup -b --exclude-device-files --exclude-fifos --exclude-sockets \
--terminal-verbosity=5 --print-statistics \
"$DIR" "$MPATH/$BACKUP/$(basename $DIR)/"
rdiff-backup --remove-older-than 100D --force \
--terminal-verbosity=5 --print-statistics \
"$MPATH/$BACKUP/$(basename $DIR)/"
done <<< "$DIRS"
# If we were mounting it, we should unmount it
if [ "$MBACKUP" = "$MPATH" ]; then
umount "$MPATH"
fi
date +"%s" > /home/cynerd/.backup_date
pkill -RTMIN+13 i3blocks
sync
echo
echo Backup finished
|