blob: 40ae7641f98be80b7a6e9a2fac3a9e64b65da0cc (
plain)
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
|
#!/usr/bin/env bash
##################################################################
# does backups (duh.) with rsync, either local or remote via ssh
# sources the file given as first parameter and acts accordingly
# example file:
#
# precommand="echo Yippee ki-yay"
# postcommand="echo done"
# remote=true
# sshUserHost="foo@bar.org"
#
# files="
# /etc
# /some/other/folder
# /some/file.sh
# "
#
##################################################################
if [ -z $1 ]; then
echo "usage: dobackup FILE"
echo "need file with backup instructions"
exit 1
fi
name=`basename $1`
source $1
timestamp=`date +"%Y%m%d-%H%M"`
dest="$HOME/backups/$name-$timestamp"
if [ "$remote" = true ]; then
if [ -z "$sshUserHost" ]; then
echo "ssh data not complete, needs sshUserHost"
exit 1
else
command="rsync -avzR -e ssh $sshUserHost:"
fi
else
command="rsync -avR "
fi
echo "$precommand"
eval ${precommand}
for file in $files; do
fullcommand="$command$file $dest"
echo "$fullcommand"
if [ "$remote" = true ]; then
$fullcommand
else
$fullcommand || exit 1
fi
done
echo "$postcommand"
eval ${postcommand}
|