-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_backup
executable file
·52 lines (40 loc) · 1.44 KB
/
server_backup
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
#!/bin/bash
LABEL=external_backup
DISK=/mnt/$LABEL
HOST=`hostname`
TARGET=$DISK/$HOST
SOURCES="/home /etc /mnt/shared"
# /mnt/shared is backed up, but we bind mount it everywhere, so don't
# back up the copies too. Also, don't back up any rsnapshot dirs.
EXCLUDES="--exclude /home/\*/shared --exclude rsnapshot --exclude .gvfs"
if [ `whoami` = 'root' ]; then
sudo mount $DISK
if [ $? != "0" ]; then
echo "Error mounting $DISK. Aborting."
else
if [ ! -d $TARGET ]; then
mkdir $TARGET
fi
date
echo `date` > $TARGET/backup_date
echo "Writing package list.."
# dpkg -l | awk '{print $2}' > $TARGET/package_list
dpkg --get-selections > $TARGET/package_list
for source in $SOURCES; do
echo "Backing up $source...."
# .gvfs is a special fuse mount and messes up rsync.
# You can use -x, but if I ever do a funky mount that I want
# automatically backed up too, I'll drive myself crazy trying
# to find out why it's not working.
#
# The eval here makes sure that the * is properly
# unescaped (but not expanded) before passing to rsync.
eval rsync -Hah --delete --delete-excluded --delete-before $EXCLUDES $source $TARGET
done
df -h $DISK
umount $DISK
echo "Done!"
fi
else
echo "run this as root"
fi