-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackup.sh
More file actions
executable file
·79 lines (65 loc) · 2 KB
/
Copy pathbackup.sh
File metadata and controls
executable file
·79 lines (65 loc) · 2 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
# Script to synchronize homedir to external host, encrypted by
# encfs --reverse.
# With extra feature to exclude directories that are not relevant
# to make backup of.
#
# REQUIRES:
# - a setup encfs --reverse from $HOME. This wil require a $HOME/.encfs6.xml
# - the password that is used for the encryption to be stored in ~/.encfs_pwd
#
# To meet these requirements; do:
#
# $ mkdir /tmp/$USER-export
# $ pwgen -s 16 1 > ~/.encfs_pwd
# $ chmod 600 ~/.encfs_pwd
# $ encfs --reverse $HOME /tmp/$USER-export
# and then use the standard options, and fill in the password
# from ~/.encfs_pwd
#
# next test it with:
# $ fusermount -u /tmp/$USER-export
# $ encfs --reverse --extpass="/bin/cat $HOME/.encfs_pwd" $HOME /tmp/$USER-export
#
# to make all encfs related info as little readable as possibe:
# $ chmod 600 ~/.encfs*
# (this includes the generated ~/.encfs6.xml as well)
#
# Done!
EXCLUDES="snap
nobackup
tmp
.cache
"
EXTERNAL_SSH=cloudsuite@myexamplebackupserver.net
EXTERNAL_STORAGE_DIR=storage/latitude-bastiaan
EXTERNAL_SNAPSHOT_DIR=storage/snapshots/latitude-bastiaan
echo_existing_excludes() {
#find if dirs actually exist
for i in $EXCLUDES; do
if [ -d $HOME/$i ]; then
echo $i
fi
done;
}
echo_exclude_opts() {
for i in $@; do
echo -n "--exclude $i "
done;
}
encrypted_excludes=`echo_existing_excludes | encfsctl encode --extpass="/bin/cat $HOME/.encfs_pwd" $HOME`
if [ -n "$XDG_RUNTIME_DIR" ] && [ -d $XDG_RUNTIME_DIR ]; then
mountpoint=$XDG_RUNTIME_DIR/home-export
else
mountpoint=/tmp/$USER-export
fi
if [ ! -d $mountpoint ]; then
mkdir $mountpoint
fi
encfs --reverse --extpass="/bin/cat $HOME/.encfs_pwd" $HOME $mountpoint
rsync -rlptvx --bwlimit=1000 --delete `echo_exclude_opts $encrypted_excludes` $mountpoint/ $EXTERNAL_SSH:$EXTERNAL_STORAGE_DIR/home/$USER
fusermount -u $mountpoint
echo Making hardlink snapshot...
today=`date +%Y_%m_%d`
ssh $EXTERNAL_SSH cp -al $EXTERNAL_STORAGE_DIR $EXTERNAL_SNAPSHOT_DIR/$today
echo done.