From e6187fc80de701bee5db84bb13d5884b3ca34e77 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 19 Feb 2016 11:30:44 -0400 Subject: Obnam: Only let one backup job run at a time when a host has multiple different backup properties, to avoid concurrent jobs fighting over scarce resources (particularly memory). Other jobs block on a lock file. --- src/Propellor/Property/Obnam.hs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/Propellor/Property/Obnam.hs') diff --git a/src/Propellor/Property/Obnam.hs b/src/Propellor/Property/Obnam.hs index 92c97f18..666328ac 100644 --- a/src/Propellor/Property/Obnam.hs +++ b/src/Propellor/Property/Obnam.hs @@ -36,6 +36,10 @@ data NumClients = OnlyClient | MultipleClients -- -- Note that this property does not make obnam encrypt the backup -- repository. +-- +-- Since obnam uses a fair amount of system resources, only one obnam +-- backup job will be run at a time. Other jobs will wait their turns to +-- run. backup :: FilePath -> Cron.Times -> [ObnamParam] -> NumClients -> Property NoInfo backup dir crontimes params numclients = backup' dir crontimes params numclients @@ -59,16 +63,18 @@ backup' dir crontimes params numclients = cronjob `describe` desc where desc = dir ++ " backed up by obnam" cronjob = Cron.niceJob ("obnam_backup" ++ dir) crontimes (User "root") "/" $ - unwords $ catMaybes - [ if numclients == OnlyClient - -- forcelock fails if repo does not exist yet - then Just $ forcelockcmd ++ " 2>/dev/null ;" - else Nothing - , Just backupcmd - , if any isKeepParam params - then Just $ "&& " ++ forgetcmd - else Nothing - ] + "flock " ++ shellEscape lockfile ++ " sh -c " ++ shellEscape cmdline + lockfile = "/var/lock/propellor-obnam.lock" + cmdline = unwords $ catMaybes + [ if numclients == OnlyClient + -- forcelock fails if repo does not exist yet + then Just $ forcelockcmd ++ " 2>/dev/null ;" + else Nothing + , Just backupcmd + , if any isKeepParam params + then Just $ "&& " ++ forgetcmd + else Nothing + ] forcelockcmd = unwords $ [ "obnam" , "force-lock" -- cgit v1.2.3