laurent22 / rsync-time-backup

Time Machine style backup with rsync.
3.41k stars 449 forks source link

built-in lock does not work for linux #149

Open kapitainsky opened 5 years ago

kapitainsky commented 5 years ago

Original check whether previous backup to the same destination is still running does not work for linux. It is at the moment:

        RUNNINGPID="$(fn_run_cmd "cat $INPROGRESS_FILE")"
        if [ "$RUNNINGPID" = "$(pgrep -o -f "$APPNAME")" ]; then
            fn_log_error "Previous backup task is still active - aborting."
            exit 1
               fi

If backup is run to local disk rsync spawns two processes and $INPROGRESS_FILE contains PID of newer rsync instance than one returned by pgrep -o -f

Also some edge cases are not caught e.g. if there is another older rsync_tmbackup backup already running (to different destination) pgrep will pick up its PID instead of one of our backup we try to lock.

I suggest to change it and use:

                RUNNINGPID="$(fn_run_cmd "cat $INPROGRESS_FILE")"
                if ps -p "$RUNNINGPID" -o command | grep "$APPNAME"
                then
                        fn_log_error "Previous backup task is still active - aborting."
                        exit 1
                fi

It is better explicitly check if process with PID from $INPROGRESS_FILE is running and it is another $APPNAME process.

I will create pull request with suggested change.