blob: 72b2a3c1db85034059519de2b6e24274478c2459 (
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
|
#!/bin/bash
#a simple backup script that uses rsync
#arg 1: source path: the path to backup.
#arg 2 (optional): destination path: absolute path on host to put src
#arg 3: rsync args
#if no destination given, src will be pushed to the given src inside of path described by ${HB_BACKUP_DIR} env var, if it exists, otherwise it will be inside of remote user's home dir
d=`date +%Y-%m-%d_%H:%M:%S`
if [[ -z $1 ]]; then
echo 'you must at least provide a source dir'
exit 0
fi
src_path="$1"
#dest='hb:/var/stor/personal/backup/'
dest_host="hb"
if [[ $HB_BACKUP_DIR ]]; then
dest_path=$HB_BACKUP_DIR"/"
else
dest_path="~/"
fi
rsargs=''
if [[ $2 ]]; then
echo 'using destination '${2}
dest_path=${2}
fi
if [[ $3 ]]; then
shift 2
rsargs=${@}
fi
dest=$dest_host":"$dest_path
#if [[ ${dest_path: -1} == "/" ]]; then
# ssh hb mkdir -p ${dest_path}
#else
# dest_parent_dir=`echo $dest_path | rev | cut -d'/' -f2- | rev`
# ssh hb mkdir -p ${dest_parent_dir}
#fi
echo "NEW BACKUP $d ${src_path} -> ${dest}" >> /var/log/datasync.log
rsync -ahAvz --protect-args -e ssh --update ${src_path} ${dest} ${rsargs} >> /var/log/datasync.log
echo "" >> /var/log/datasync.log
#if [[ TODO "%"` ]]; then
# echo "Complete."
#else
# echo "!! ${src} not uploaded. Server version is newer."
#fi
|