summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Attic.hs
diff options
context:
space:
mode:
authorFélix Sipma2016-04-28 21:32:28 +0200
committerFélix Sipma2016-04-28 21:32:28 +0200
commited52eec11b61d59b7a139b8f55c59961b0806d96 (patch)
treeb3533036bd8f14ff12fdbfd23e42582570a63e57 /src/Propellor/Property/Attic.hs
parentf70e58b707a93f2977fbba6b98d89441e0ea3b31 (diff)
Attic: 'restored' and 'backup' only take one directory (API change)
Diffstat (limited to 'src/Propellor/Property/Attic.hs')
-rw-r--r--src/Propellor/Property/Attic.hs30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/Propellor/Property/Attic.hs b/src/Propellor/Property/Attic.hs
index 9fc79abd..504e3cfb 100644
--- a/src/Propellor/Property/Attic.hs
+++ b/src/Propellor/Property/Attic.hs
@@ -34,8 +34,9 @@ init backupdir = check (not <$> repoExists backupdir) (cmdProperty "attic" inita
, backupdir
]
-restored :: [FilePath] -> AtticRepo -> Property DebianLike
-restored dirs backupdir = cmdProperty "attic" restoreargs
+-- TODO: use restored from Obnam
+restored :: FilePath -> AtticRepo -> Property DebianLike
+restored dir backupdir = cmdProperty "attic" restoreargs
`assume` MadeChange
`describe` ("attic restore from " ++ backupdir)
`requires` installed
@@ -43,15 +44,22 @@ restored dirs backupdir = cmdProperty "attic" restoreargs
restoreargs =
[ "extract"
, backupdir
+ , dir
]
- ++ dirs
-backup :: [FilePath] -> AtticRepo -> Cron.Times -> [AtticParam] -> [KeepPolicy] -> Property DebianLike
-backup dirs backupdir crontimes extraargs kp = propertyList (backupdir ++ " attic backup") $ props
- & check (not <$> repoExists backupdir) (restored dirs backupdir)
- & Cron.niceJob ("attic_backup" ++ backupdir) crontimes (User "root") "/" backupcmd
+backup :: FilePath -> AtticRepo -> Cron.Times -> [AtticParam] -> [KeepPolicy] -> Property DebianLike
+backup dir backupdir crontimes extraargs kp = backup' dir backupdir crontimes extraargs kp
+ `requires` restored dir backupdir
+
+backup' :: FilePath -> AtticRepo -> Cron.Times -> [AtticParam] -> [KeepPolicy] -> Property DebianLike
+backup' dir backupdir crontimes extraargs kp = cronjob
+ `describe` desc
`requires` installed
where
+ desc = backupdir ++ " attic backup"
+ cronjob = Cron.niceJob ("attic_backup" ++ dir) crontimes (User "root") "/" $
+ "flock " ++ shellEscape lockfile ++ " sh -c " ++ backupcmd
+ lockfile = "/var/lock/propellor-attic.lock"
backupcmd = intercalate ";" $
createCommand
: if null kp then [] else [pruneCommand]
@@ -60,14 +68,14 @@ backup dirs backupdir crontimes extraargs kp = propertyList (backupdir ++ " atti
, "create"
, "--stats"
]
- ++ extraargs ++
- [ backupdir ++ "::" ++ "$(date --iso-8601=ns --utc)"
- , unwords dirs
+ ++ map shellEscape extraargs ++
+ [ shellEscape backupdir ++ "::" ++ "$(date --iso-8601=ns --utc)"
+ , shellEscape dir
]
pruneCommand = unwords $
[ "attic"
, "prune"
- , backupdir
+ , shellEscape backupdir
]
++
map keepParam kp