-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrdiffback.sh
executable file
·45 lines (37 loc) · 1.2 KB
/
rdiffback.sh
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
#!/bin/sh
# Where the backups go, this is an sshfs mount for me
DESTINATION="/home/sontek/backups/"
LOG="/var/log/backup/"
TIMESTAMP=`date +%m%d_%H%M`
# How long to keep backup history (6 months)
MAXAGE="6M"
# Options from man page
OPTIONS="--force --print-statistics --exclude **.iso"
# Make sure $DESTINATION exists
if [ ! -d "$DESTINATION" ]; then
echo "Error: '$DESTINATION' does not exist!!"
exit 1
fi
# Check if rdiff-backup exists
if ! which rdiff-backup; then
echo "You need to install rdiff-backup"
exit 1
fi
# Just put all the folders you want backed here.
for SOURCE in "/home/sontek/dotfiles/"
do
if [ ! -d "$DESTINATION/$SOURCE" ]; then
echo "Creating folder $DESTINATION/$SOURCE"
mkdir -p "$DESTINATION/$SOURCE"
fi
echo "Backup: rdiff-backup $OPTIONS $SOURCE $DESTINATION/$SOURCE"
rdiff-backup $OPTIONS "$SOURCE" "$DESTINATION/$SOURCE"
# It went well, remove stuff older than MAXAGE
if [ "$?" -eq 0 ]; then
echo "Cleanup: rdiff-backup --force --remove-older-than $MAXAGE
$DESTINATION/$SOURCE"
rdiff-backup --force --remove-older-than $MAXAGE "$DESTINATION/$SOURCE"
else
echo $? > $LOG/fail$TIMESTAMP.log
fi
done