@@ -51,7 +51,6 @@ ha_sync_send() {
5151 local cfg=$1
5252 local address ssh_key ssh_port sync_list sync_dir sync_file count exclude_list
5353 local ssh_options ssh_remote dirs_list files_list
54- local changelog=" /tmp/changelog"
5554 local restore_list=" /tmp/restore_list"
5655
5756 config_get address " $cfg " address
@@ -83,58 +82,28 @@ ha_sync_send() {
8382
8483 # shellcheck disable=SC2086
8584 timeout 10 ssh $ssh_options $ssh_remote mkdir -m 755 -p " /tmp" || {
86- log_err " can not connect to $address . check key or connection"
85+ log_err " Can not connect to $address . check key or connection"
8786 update_last_sync_time " $cfg "
8887 update_last_sync_status " $cfg " " SSH Connection Failed"
8988 return 0
9089 }
9190
9291 # shellcheck disable=SC2086
93- if rsync --out-format=' %n' --dry-run -a --relative ${files_list} -e " ssh $ssh_options " --rsync-path=" sudo rsync" " $ssh_remote " :" $sync_dir " > " $changelog " ; then
94- count=$( wc -l " $changelog " )
95- if [ " ${count%% * } " = " 0" ]; then
96- log_debug " all files are up to date"
97- update_last_sync_time " $cfg "
98- update_last_sync_status " $cfg " " Up to Date"
99- return 0
100- fi
101- else
102- log_err " rsync dry run failed for $address "
103- update_last_sync_time " $cfg "
104- update_last_sync_status " $cfg " " Rsync Detection Failed"
105- return 0
106- fi
107-
108- # shellcheck disable=SC2086
109- rsync -a --relative ${files_list} ${changelog} ${restore_list} -e " ssh $ssh_options " --rsync-path=" sudo rsync" " $ssh_remote " :" $sync_dir " || {
110- log_err " rsync transfer failed for $address "
92+ rsync -a --relative --delete-after ${files_list} ${restore_list} -e " ssh $ssh_options " --rsync-path=" rsync" " $ssh_remote " :" $sync_dir " || {
93+ log_err " Configuration sync transfer failed for $address "
11194 update_last_sync_time " $cfg "
11295 update_last_sync_status " $cfg " " Rsync Transfer Failed"
96+ return 0
11397 }
11498
115- log_info " keepalived sync is completed for $address "
99+ log_info " Configuration sync completed for $address "
116100 # Invoke detached hotplug on the backup node
117101 ssh $ssh_options $ssh_remote " ACTION=NOTIFY_SYNC /usr/bin/setsid /sbin/hotplug-call keepalived &" & > /dev/null
118102 update_last_sync_time " $cfg "
119103 update_last_sync_status " $cfg " " Successful"
120104
121105}
122106
123- ha_sync_receive () {
124- local cfg=$1
125- local ssh_pubkey
126- local name auth_file home_dir
127-
128- config_get name " $cfg " name
129- config_get sync_dir " $cfg " sync_dir " $RSYNC_HOME "
130- [ -z " $sync_dir " ] && return 0
131- config_get ssh_pubkey " $cfg " ssh_pubkey
132- [ -z " $ssh_pubkey " ] && return 0
133-
134- /etc/init.d/keepalived-inotify enabled || /etc/init.d/keepalived-inotify enable
135- /etc/init.d/keepalived-inotify running " $name " || /etc/init.d/keepalived-inotify start " $name "
136- }
137-
138107ha_sync_each_peer () {
139108 local cfg=" $1 "
140109 local c_name=" $2 "
@@ -151,7 +120,7 @@ ha_sync_each_peer() {
151120
152121 case " $sync_mode " in
153122 send) ha_sync_send " $cfg " ;;
154- receive) ha_sync_receive " $cfg " ;;
123+ receive) ;;
155124 esac
156125}
157126
@@ -167,7 +136,7 @@ main() {
167136 local lockfile=" /var/lock/keepalived-rsync.lock"
168137
169138 if ! lock -n " $lockfile " > /dev/null 2>&1 ; then
170- log_info " another process is already running"
139+ log_info " Another process is already running"
171140 return 1
172141 fi
173142
0 commit comments