NEW: rsync script with logs

This commit is contained in:
xpk 2021-07-08 11:21:14 +08:00
parent a7cb56a514
commit 4d0c692bf0
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86

29
sh/rsync-job.sh Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env bash
function log() {
echo "$(date -u): /opt/rxt/nfs-rsync.sh - $@" >> /var/log/nfs-rsync-job.log
}
# Empty previous log
truncate -s0 /var/log/nfs-rsync.log
# First check that /content is mounted
if grep -q /content /proc/mounts ; then
log target mount exist, continuing.
else
log FAILED. target mount is missing.
exit 1
fi
# Check if rsync is already running
if pgrep -f 'rsync.*/var/log/nfs-rsync.log'; then
log WARNING. another instance of /opt/rxt/nfs-rsync.sh is already running. skipping this run.
exit 1
fi
if rsync -axz --delete-delay --ignore-missing-args --stats --log-file=/var/log/nfs-rsync.log 192.168.102.62:/san/nfs-fs/ /content/; then
log OK. rsync completed successfully
else
log FAILED. rsync did not complete with exit code $?. please refer to /var/log/nfs-rsync.log for additional details.
fi