-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup-root-rsync
More file actions
executable file
·62 lines (46 loc) · 1.66 KB
/
backup-root-rsync
File metadata and controls
executable file
·62 lines (46 loc) · 1.66 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
show_help () {
/usr/bin/cat <<END_OF_SHOW_HELP
$0 -d <DESTDIR> -h <HOSTNAME> -k <KEYFILE> -s <SERVICES>
-d Directory on remote server where backup will be made
-h Hostname to connect to.
-k Location of key to use
-s Services to stop/start before/after backup
-u User to connect as
END_OF_SHOW_HELP
}
[[ $EUID != 0 ]] && echo "Must have super user privileges." && exit 1
OPTIND=1
while getopts "d:h:k:s:u:" opt; do
case "$opt" in
d) rdir=$OPTARG;;
h) host=$OPTARG;;
k) kfil=$OPTARG;;
s) svcs=$OPTARG;;
u) user=$OPTARG;;
'?') show_help >&2 && exit 1;;
esac
done
shift $((OPTIND-1))
[ -z ${kfil} ] && sshc="ssh" || sshc="ssh -i ${kfil}"
xcld+="--exclude swapfile "
xcld+="--exclude .thumbnails "
xcld+="--exclude .cache "
xcld+="--exclude Trash "
xcld+="--exclude /var/cache/pacman "
xcld+="--exclude /srv/build/x86_64/aurpbs "
xcld+="--exclude /srv/build/i686/aurpbs "
[ -t 1 ] && rsop="${xcld} --del --delete-excluded --progress -xaze"
[ -t 1 ] || rsop="${xcld} --del --delete-excluded -qxaze"
for binds in `/usr/bin/cat /etc/fstab | /usr/bin/grep bind | /usr/bin/sed 's/\t/ /g' | /usr/bin/sed 's/ */ /g' | /usr/bin/cut -d\ -f2`; do
[ -t 1 ] && echo Unbinding ${binds}...
/usr/bin/umount ${binds}
done
[ "${svcs}" != "none" ] && { [ -t 1 ] && echo "Stopping ${svcs}..."; } && /usr/bin/systemctl stop ${svcs}
touch /.bkupstmp
[ -t 1 ] && echo "Rsyncing to ${user}@${host}..."
/usr/bin/rsync ${rsop} "${sshc}" / ${user}@${host}:${rdir}
[ "${svcs}" != "none" ] && { [ -t 1 ] && echo "Restarting ${svcs}..."; } && /usr/bin/systemctl start ${svcs}
[ -t 1 ] && echo "Rebinding mounts..."
/usr/bin/mount -a
exit 0