summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma2016-04-22 16:24:42 +0200
committerFélix Sipma2016-04-22 16:24:42 +0200
commit1e988fdf8a3ec2d0313c67e74036bed1a2a578f6 (patch)
treec3a94c5ce2cc1cbb4d14caab90451b3885ed1d70
parent2676a68ce19cf6c05a55790c4b8e2b377ae63dd8 (diff)
Attic: add KeepPolicy
-rw-r--r--src/Propellor/Property/Attic.hs40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/Propellor/Property/Attic.hs b/src/Propellor/Property/Attic.hs
index 961b681a..3d857913 100644
--- a/src/Propellor/Property/Attic.hs
+++ b/src/Propellor/Property/Attic.hs
@@ -1,12 +1,22 @@
-- | Maintainer: Félix Sipma <felix+propellor@gueux.org>
-module Propellor.Property.Attic where
+module Propellor.Property.Attic
+ ( installed
+ , repoExists
+ , init
+ , restored
+ , backup
+ , KeepPolicy (..)
+ ) where
-import Propellor.Base
+import Propellor.Base hiding (init)
+import Prelude hiding (init)
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Cron as Cron
import Data.List (intercalate)
+type AtticParam = String
+
installed :: Property DebianLike
installed = Apt.installed ["attic"]
@@ -34,8 +44,8 @@ restored dirs backupdir = cmdProperty "attic" restoreargs
]
++ dirs
-backup :: [FilePath] -> FilePath -> Cron.Times -> [String] -> Property DebianLike
-backup dirs backupdir crontimes extraargs = propertyList (backupdir ++ " attic backup") $ props
+backup :: [FilePath] -> FilePath -> 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
`requires` installed
@@ -53,12 +63,24 @@ backup dirs backupdir crontimes extraargs = propertyList (backupdir ++ " attic b
[ backupdir ++ "::" ++ "$(date --iso-8601=ns --utc)"
, unwords dirs
]
- pruneCommand = unwords
+ pruneCommand = unwords $
[ "attic"
, "prune"
, backupdir
- , "--keep-daily=7"
- , "--keep-weekly=4"
- , "--keep-monthly=6"
- , "--keep-yearly=1"
]
+ ++
+ map keepParam kp
+
+keepParam :: KeepPolicy -> AtticParam
+keepParam (KeepHours n) = "--keep-hourly=" ++ show n
+keepParam (KeepDays n) = "--keep-daily=" ++ show n
+keepParam (KeepWeeks n) = "--keep-daily=" ++ show n
+keepParam (KeepMonths n) = "--keep-monthly=" ++ show n
+keepParam (KeepYears n) = "--keep-yearly=" ++ show n
+
+data KeepPolicy
+ = KeepHours Int
+ | KeepDays Int
+ | KeepWeeks Int
+ | KeepMonths Int
+ | KeepYears Int