-
Notifications
You must be signed in to change notification settings - Fork 2
/
dirsync
executable file
·59 lines (52 loc) · 1.28 KB
/
dirsync
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
#!/bin/bash
# Example script to non-recursively backup an entire directory.
# If files are in-use, a snapshot (ie: via ZFS) should be taken.
# Functions
print_usage() {
echo "Usage: dirsync <srcdir> <user@dsthost> <dstdir>"
exit 0
}
# Option parsing
while getopts ":h:q" opt; do
case $opt in
q)
options="-q"
;;
h)
print_usage
;;
\?)
print_usage
;;
esac
done
shift $((OPTIND-1))
# Argument parsing
if [ $# -ne 3 ]; then
print_usage
fi
# Variables
srcdir=`dirname "$1/."`
dstdir=`dirname "$3/."`
dsthost=$2
spaced=false
local_exit_code=0
global_exit_code=0
# Argument checking
echo $srcdir | grep -q "[[:space:]]" && spaced=true
echo $dstdir | grep -q "[[:space:]]" && spaced=true
echo $dsthost | grep -q "[[:space:]]" && spaced=true
$spaced && echo "blocksync does not support path with spaces, exiting..." && exit 1
# Backup
oldIFS=$IFS; IFS=$'\n'
for image in `ls $srcdir`; do
echo $image | grep -q "[[:space:]]" && spaced=true
$spaced && global_exit_code=2 && echo "path with spaces are not supported, skipping $image" && continue
/root/blocksync.py $options -f $srcdir/$image $dsthost $dstdir/$image; local_exit_code=$?
if [ $local_exit_code -ne 0 ]; then
global_exit_code=$local_exit_code
fi
done
IFS=$oldIFS
# Cleanup and exit
exit $global_exit_code