-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·58 lines (43 loc) · 1.14 KB
/
sync.sh
File metadata and controls
executable file
·58 lines (43 loc) · 1.14 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
#!/bin/bash
#
# sync.sh
# ================
# A simple script for synchronizing files using rsync.
source_dir=${1}
dest_dir=${2}
function print_usage {
echo "usage: sync.sh SOURCE_DIR DESTINATION_DIR"
}
if [ -z "$source_dir" ]; then
print_usage
exit 1
fi
if [ -z "$dest_dir" ]; then
print_usage
exit 1
fi
if [ ! -d "$source_dir" ]; then
echo "Source directory doesn't exists: $source_dir" >&2
exit 2
fi
if [ ! -d "$dest_dir" ]; then
echo "Source directory doesn't exists: $dest_dir" >&2
exit 3
fi
echo "Running in dry run:"
# RSYNC_EXTRA_PARAMS allows to hook up special params when calling sync.sh from different scripts
RSYNC_OPTS="${RSYNC_EXTRA_PARAMS} -av"
# grep skips directories in output
rsync $RSYNC_OPTS -n "$source_dir" "$dest_dir" | grep -v '/$'
echo ""
echo "INFO: Running without --delete option. No files will be removed."
echo ""
read -p "Would you like to proceed? [y/n]: " input
until [ $input == "y" -o $input == "n" ]; do
read -p "Would you like to proceed? Enter \"y\" or \"n\": " input
done
if [ $input == "n" ]; then
exit 0
fi
echo "syncing..."
rsync $RSYNC_OPTS "$source_dir" "$dest_dir"