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
|
$ cat /home/tomcat/scripts/sync.sh
#!/bin/bash
src_path="/home/tomcat/install_jre_tomcat/"
dest_path="/home/tomcat/install_jre_tomcat/"
dest_user="tomcat"
dest_ip="172.16.2.182"
log_path="/home/tomcat/scripts/sync.log"
if [ ! -e "$(dirname $log_path)" ]; then
mkdir -p "$(dirname $log_path)"
fi
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M:%S' --format '%T|%w%f|%e' -e close_write,delete,create,attrib $src_path | while read file; do
f_name="$(echo $file | awk -F '|' '{print $2}')"
if [[ $(basename "$f_name") =~ ^\..* ]]; then
continue
fi
if [ -f "$f_name" ]; then
file_dest_path="$(dirname $f_name)/"
rsync -vzrtopg --progress "$f_name" $dest_user@$dest_ip:$file_dest_path >>"$log_path" 2>&1
echo "file ${file} was rsynced" >>"$log_path"
else
rsync -vzrtopg --progress "$src_path" $dest_user@$dest_ip:$dest_path >>"$log_path" 2>&1
echo "dir ${file} was rsynced" >>"$log_path"
fi
done
|