1
I have cron job that runs an rsync command that does a remote backup every two hours.
In the event that the previous remote backup is still running, I've encapsulated this rysnc command inside of a flock command.
Flock prevents this command from running multiple times simultaneously:
flock -n /location/of/lock_file -c 'rsync -rv /home/localuser/ remoteuser@55.55.55.55:/home/remoteuser/backupFolder' || echo "Couldn't perform remote backup, because previous remote backup is still in progress."
However, if I reboot the remote server during one of these backups (to simulate a broken connection scenario), flock continues to block future attempts because the previous process (although permanently disconnected from the backup destination) persists.
What's the best way to make flock know that rsync has failed indefinitely, and therefore release these locks that are preventing future attempts from getting started?
On the rsync man page, I see there is a --timeout argument. Is setting that the best way to deal with flock's around-the-clocks locks?
1
Perhaps solo which uses a bound socket to prevent multiple cron instances from running simultaneously; would work better than
– Dan D. – 2013-12-02T19:26:14.480flock
for you?