I have an rsync command for copying across data from my ~/home to the remote /srv/share folder.

/usr/bin/rsync -rltvz --progress --stats -e 'ssh -p MYPORT' /home/luke/share/ [email protected]:/srv/share/

1) I would like to automate this so that anything dropped in the local ~/share will just be copied across, I was tempted to do an hourly cron job or use a systemd Timer but I'm worried that if it is doing a big job and it takes more than one hour - then two simultanous rsync insantiations will be operating on the same data. Is that the case? If so, how can I avoid it?

2) Is there any problem with multiple rsyncs from different machines copying (different) data into the same server dir at the same time?


1 Answer 1


I ran into this exact same problem with Timeshift. I added this to the top of my backup script so it would not start until after Timeshift had completed:

# if Timeshift is running, wait until it's finished
until [ -z $(/bin/pidof timeshift) ]
      # waiting
      sleep 1

Just substitute rsync for Timeshift and you should be good to go.

If you want to put everything on one long command, do this:

until [ -z $(/bin/pidof rsync) ]; do sleep 1; done; your_rsync_command
  • until [ -z $(/bin/pidof rsync) ] do echo "it works!" /usr/bin/rsync -rltvz --progress --stats -e 'ssh -p MYPORT' /home/luke/share/ [email protected]:/srv/share/ sleep 3000 done
    – ezekiel
    Commented Jan 31, 2020 at 17:02
  • unfortunately it's not working - I'm executing it when there is no instance of rsync running in the background (pidof rsync returns nothing) and the "until" just exits immediately, rather than executing the internal echo and rsync.
    – ezekiel
    Commented Jan 31, 2020 at 17:04
  • Then it's working by design. Check my updated answer. Commented Jan 31, 2020 at 17:08
  • OK say I had this running as an hourly cron job / timer but my rsync job took 6 hours. So when it finished there would be 6 rsync instances waiting to launch. Now in that moment there wouldn't be anything new to transfer but it's possible, that two or more rsync instances would launch simultanaously if they were both released from the UNTIL block at about the same time, could that cause a problem?
    – ezekiel
    Commented Feb 1, 2020 at 9:03
  • given that concern^ I might adapt to just exit on "until" rather than wait. But the basic solution of checking [ -z $(/bin/pidof rsync) ] is still the same. Would you accept such an edit?
    – ezekiel
    Commented Feb 1, 2020 at 9:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .