diff options
| author | Laurent Cozic <laurent22@users.noreply.github.com> | 2017-06-03 14:54:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-03 14:54:10 +0100 |
| commit | 8f8fbeb130160a9e068b91db8eb138721d11469a (patch) | |
| tree | 888f658218c05d7188af1d1054852419c1268815 | |
| parent | d152279d301bf799c496d00d9b2aa706b46e88c6 (diff) | |
| parent | dbc2f536fab5afb9f4a97913dae20bdbffb5c1c8 (diff) | |
Merge pull request #80 from dovecode/cygwin-conflict-support
Add cygwin support for checking if the previous backup is still running
| -rwxr-xr-x | rsync_tmbackup.sh | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index ec643fa..03a7689 100755 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -269,10 +269,20 @@ fi if [ -n "$(fn_find "$INPROGRESS_FILE")" ]; then if [ "$OSTYPE" == "cygwin" ]; then - # TODO: Cygwin reports the name of currently running Bash scripts as just "/usr/bin/bash" - # TODO: so the pgrep solution below won't work. Need to use "procps -wwFAH", grep - # TODO: the script name, and extract the process ID from it. - fn_log_warn "Cygwin only: Previous backup task has either been interrupted or it might still be active, but there is currently no check for this. Assuming that the task was simply interrupted." + # 1. Grab the PID of previous run from the PID file + RUNNINGPID="$(fn_run_cmd "cat $INPROGRESS_FILE")" + + # 2. Get the command for the process currently running under that PID and look for our script name + RUNNINGCMD="$(procps -wwfo cmd -p $RUNNINGPID --no-headers | grep "$APPNAME")" + + # 3. Grab the exit code from grep (0=found, 1=not found) + GREPCODE=$? + + # 4. if found, assume backup is still running + if [ "$GREPCODE" = 0 ]; then + fn_log_error "Previous backup task is still active - aborting (command: $RUNNINGCMD)." + exit 1 + fi else RUNNINGPID="$(fn_run_cmd "cat $INPROGRESS_FILE")" if [ "$RUNNINGPID" = "$(pgrep "$APPNAME")" ]; then |
