From 4d0c692bf025ebb7f5c1f140d289a773c17d0003 Mon Sep 17 00:00:00 2001 From: x p k Date: Thu, 8 Jul 2021 11:21:14 +0800 Subject: [PATCH] NEW: rsync script with logs --- sh/rsync-job.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 sh/rsync-job.sh diff --git a/sh/rsync-job.sh b/sh/rsync-job.sh new file mode 100644 index 0000000..2c4133a --- /dev/null +++ b/sh/rsync-job.sh @@ -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 +