summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma2016-04-01 11:08:15 +0200
committerFélix Sipma2016-04-22 15:38:47 +0200
commitd324a3bc1d122527836d012078dcd632ebb78495 (patch)
tree33daa3bef3a557e251633998f7e090431cbb092a
parentc7bacb2f33b0d539a108dc8f6636e71574c47d53 (diff)
add Attic property
-rw-r--r--propellor.cabal5
-rw-r--r--src/Propellor/Property/Attic.hs48
2 files changed, 51 insertions, 2 deletions
diff --git a/propellor.cabal b/propellor.cabal
index 7f12cbec..215836ac 100644
--- a/propellor.cabal
+++ b/propellor.cabal
@@ -53,7 +53,7 @@ Executable propellor-config
GHC-Options: -threaded -Wall -fno-warn-tabs -O0
Extensions: TypeOperators
Hs-Source-Dirs: src
- Build-Depends:
+ Build-Depends:
base >= 4.5, base < 5,
MissingH, directory, filepath, IfElse, process, bytestring, hslogger,
unix, unix-compat, ansi-terminal, containers (>= 0.5), network, async,
@@ -63,7 +63,7 @@ Library
GHC-Options: -Wall -fno-warn-tabs -O0
Extensions: TypeOperators
Hs-Source-Dirs: src
- Build-Depends:
+ Build-Depends:
base >= 4.5, base < 5,
MissingH, directory, filepath, IfElse, process, bytestring, hslogger,
unix, unix-compat, ansi-terminal, containers (>= 0.5), network, async,
@@ -78,6 +78,7 @@ Library
Propellor.Property.Apache
Propellor.Property.Apt
Propellor.Property.Apt.PPA
+ Propellor.Property.Attic
Propellor.Property.Cmd
Propellor.Property.Concurrent
Propellor.Property.Conductor
diff --git a/src/Propellor/Property/Attic.hs b/src/Propellor/Property/Attic.hs
new file mode 100644
index 00000000..f2e0cbf1
--- /dev/null
+++ b/src/Propellor/Property/Attic.hs
@@ -0,0 +1,48 @@
+-- | Maintainer: Félix Sipma <felix+propellor@gueux.org>
+
+module Propellor.Property.Attic where
+
+import Propellor.Base
+import qualified Propellor.Property.Apt as Apt
+import qualified Propellor.Property.Cron as Cron
+import Data.List (intercalate)
+
+installed :: Property NoInfo
+installed = Apt.installed ["attic"]
+
+repoExists :: FilePath -> IO Bool
+repoExists repo = boolSystem "attic" [Param "list", File repo]
+
+backup :: [FilePath] -> FilePath -> Cron.Times -> [String] -> Property NoInfo
+backup dirs backupdir crontimes extraargs = propertyList (backupdir ++ " attic backup")
+ [ installed
+ , check (not <$> repoExists backupdir) $ cmdProperty "/usr/bin/attic" initargs
+ , Cron.niceJob ("attic_backup" ++ backupdir) crontimes (User "root") "/" backupcmd
+ ]
+ where
+ initargs =
+ [ "init"
+ , backupdir
+ ]
+ backupcmd = intercalate ";"
+ [ createCommand
+ , pruneCommand
+ ]
+ createCommand = unwords $
+ [ "/usr/bin/attic"
+ , "create"
+ , "--stats"
+ ]
+ ++ extraargs ++
+ [ backupdir ++ "::" ++ "$(date --iso-8601=ns --utc)"
+ , unwords dirs
+ ]
+ pruneCommand = unwords
+ [ "/usr/bin/attic"
+ , "prune"
+ , backupdir
+ , "--keep-daily=7"
+ , "--keep-weekly=4"
+ , "--keep-monthly=6"
+ , "--keep-yearly=1"
+ ]