-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud-backup.sh
47 lines (38 loc) · 1.36 KB
/
cloud-backup.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
46
47
#!/bin/bash
# This backup script backups files with rsync to a storage through sshfs.
# Deleted files on source will be deleted on the destination ("--delete"
# parameter in rsync command). This script is reccommended to use as a second
# backup destinations
# dirs without a slash at the end
sourcedir=/home/dhw
backupdir=/media/dhw/hetzner
logdir=/home/dhw/Backup/log
# rsync exclude file, path has to be relative to the sourcedir
excludefile=$(dirname "$0")/cloud-exclude.txt
label=dhw
ssh_identiyfile=/home/dhw/.ssh/cloud_key
# storage url file has to look like "[email protected]"
ssh_storageurl=`cat /home/dhw/.ssh/storage_url`
#mount backup direcorty with sshfs
sshfs $ssh_storageurl:/ $backupdir -o IdentityFile=$ssh_identiyfile -o idmap=user -o uid=$(id -u) -o gid=$(id -g)
# int_handler makes sure, the destination is unmounted
int_handler()
{
echo "Interrupted."
# Kill the parent process of the script.
kill $PPID
fusermount -u $backupdir
exit 1
}
trap 'int_handler' INT
if mount | grep $backupdir > /dev/null; then
rsync -avzk --delete --log-file=$logdir/cloud-backup_$(date +'%Y%m%d').log --exclude-from=$excludefile "$sourcedir/" "$backupdir/$label"
else
echo "Backup drive not found!"
fi
# unmount backup dirs
fusermount -u $backupdir
echo "Fertig!"
read -p "Drücke ENTER um dieses Fenster zu schliessen"
# We never reach this part.
exit 0