[GRLUG] using flock

Jeff DeFouw mrj at plorb.com
Tue Dec 24 12:49:19 EST 2013


On Tue, Dec 24, 2013 at 09:17:09AM -0500, Eric Beversluis wrote:
> I've got a backup program on a server that includes a mysqldump once a
> day which overwrites the existing sysmyqldump.sql. The script also does
> rsync (of zarafa-backup, the mysqldump, and /var/lib/zarafa (the zarafa
> attachments file) to an external hard drive. Once a month is also copies
> the sysmysqldump.sql that's on the external HDD to a file with that
> day's date attached.
> 
> The cron is set to run every hour. Right now, mysqldump is finishing at
> 40 min past the hour (00:40), so I think that when it also tries to make
> the copy on the 1st of the month it will run over into the next hour.
> 
> As I understand it, the thing to do to prevent the script starting over
> before the old one finishes is to use 'flock.'
> 
> My question is this: How does cron respond if flock prevents the script
> from starting at 01:00? Does it start it when the flock is freed or just
> skip that cycle or what?

Flock can create a blocking lock that pauses execution.  If you use 
flock without any timeouts, it will wait indefinitely until the lock is 
available.  Your script will just sit there idle during that time.  When 
the lock becomes available, it will continue execution.

-- 
Jeff DeFouw <mrj at plorb.com>


More information about the grlug mailing list