summaryrefslogtreecommitdiff
path: root/src/Propellor
diff options
context:
space:
mode:
authorJoey Hess2016-02-06 20:04:00 -0400
committerJoey Hess2016-02-06 20:04:00 -0400
commit74a02add291f13b27fb6a1813b870a0730e1142b (patch)
tree846cb9175b433b9e7dd1a717ecd336280e56c5ef /src/Propellor
parentb460eefde075e5f6734ccfb8810b4e07516bba12 (diff)
Obnam: To cause old generations to be forgotten, keepParam can be passed to a backup property; this causes obnam forget to be run.
Diffstat (limited to 'src/Propellor')
-rw-r--r--src/Propellor/Property/Obnam.hs45
-rw-r--r--src/Propellor/Property/SiteSpecific/JoeySites.hs3
2 files changed, 43 insertions, 5 deletions
diff --git a/src/Propellor/Property/Obnam.hs b/src/Propellor/Property/Obnam.hs
index 091a6d90..684c424e 100644
--- a/src/Propellor/Property/Obnam.hs
+++ b/src/Propellor/Property/Obnam.hs
@@ -25,9 +25,7 @@ data NumClients = OnlyClient | MultipleClients
--
-- So, this property can be used to deploy a directory of content
-- to a host, while also ensuring any changes made to it get backed up.
--- And since Obnam encrypts, just make this property depend on a gpg
--- key, and tell obnam to use the key, and your data will be backed
--- up securely. For example:
+-- For example:
--
-- > & Obnam.backup "/srv/git" "33 3 * * *"
-- > [ "--repository=sftp://2318@usw-s002.rsync.net/~/mygitrepos.obnam"
@@ -35,13 +33,16 @@ data NumClients = OnlyClient | MultipleClients
-- > `requires` Ssh.keyImported SshRsa "root" (Context hostname)
--
-- How awesome is that?
+--
+-- Note that this property does not make obnam encrypt the backup
+-- repository.
backup :: FilePath -> Cron.Times -> [ObnamParam] -> NumClients -> Property NoInfo
backup dir crontimes params numclients =
backup' dir crontimes params numclients
`requires` restored dir params
-- | Like backup, but the specified gpg key id is used to encrypt
--- the repository.
+-- the repository.
--
-- The gpg secret key will be automatically imported
-- into root's keyring using Propellor.Property.Gpg.keyImported
@@ -58,7 +59,7 @@ backup' dir crontimes params numclients = cronjob `describe` desc
where
desc = dir ++ " backed up by obnam"
cronjob = Cron.niceJob ("obnam_backup" ++ dir) crontimes (User "root") "/" $
- intercalate ";" $ catMaybes
+ intercalate "&&" $ catMaybes
[ if numclients == OnlyClient
then Just $ unwords $
[ "obnam"
@@ -70,6 +71,12 @@ backup' dir crontimes params numclients = cronjob `describe` desc
, "backup"
, shellEscape dir
] ++ map shellEscape params
+ , if any isKeepParam params
+ then Just $ unwords $
+ [ "obnam"
+ , "forget"
+ ] ++ map shellEscape params
+ else Nothing
]
-- | Restores a directory from an obnam backup.
@@ -107,5 +114,33 @@ restored dir params = property (dir ++ " restored by obnam") go
, return FailedChange
)
+-- | Policy for backup generations to keep. For example, KeepDays 30 will
+-- keep the latest backup for each day when a backup was made, and keep the
+-- last 30 such backups. When multiple KeepPolicies are combined together,
+-- backups meeting any policy are kept. See obnam's man page for details.
+data KeepPolicy
+ = KeepHours Int
+ | KeepDays Int
+ | KeepWeeks Int
+ | KeepMonths Int
+ | KeepYears Int
+
+-- | Constructs an ObnamParam that specifies which old backup generations
+-- to keep. By default, all generations are kept. However, when this parameter
+-- is passed to the `backup` or `backupEncrypted` properties, they will run
+-- obnam forget to clean out generations not specified here.
+keepParam :: [KeepPolicy] -> ObnamParam
+keepParam ps = "--keep=" ++ intercalate "," (map go ps)
+ where
+ go (KeepHours n) = mk n 'h'
+ go (KeepDays n) = mk n 'd'
+ go (KeepWeeks n) = mk n 'w'
+ go (KeepMonths n) = mk n 'm'
+ go (KeepYears n) = mk n 'y'
+ mk n c = show n ++ [c]
+
+isKeepParam :: ObnamParam -> Bool
+isKeepParam p = "--keep=" `isPrefixOf` p
+
installed :: Property NoInfo
installed = Apt.installed ["obnam"]
diff --git a/src/Propellor/Property/SiteSpecific/JoeySites.hs b/src/Propellor/Property/SiteSpecific/JoeySites.hs
index 7e6d3f8c..03f2efcb 100644
--- a/src/Propellor/Property/SiteSpecific/JoeySites.hs
+++ b/src/Propellor/Property/SiteSpecific/JoeySites.hs
@@ -140,6 +140,7 @@ oldUseNetServer hosts = propertyList "olduse.net server" $ props
[ "--repository=sftp://2318@usw-s002.rsync.net/~/olduse.net"
, "--client-name=spool"
, "--ssh-key=" ++ keyfile
+ , Obnam.keepParam [Obnam.KeepDays 30]
] Obnam.OnlyClient
`requires` Ssh.userKeyAt (Just keyfile)
(User "root")
@@ -194,6 +195,7 @@ mumbleServer hosts = combineProperties hn $ props
[ "--repository=sftp://2318@usw-s002.rsync.net/~/" ++ hn ++ ".obnam"
, "--ssh-key=" ++ sshkey
, "--client-name=mumble"
+ , Obnam.keepParam [Obnam.KeepDays 30]
] Obnam.OnlyClient
`requires` Ssh.userKeyAt (Just sshkey)
(User "root")
@@ -213,6 +215,7 @@ gitServer hosts = propertyList "git.kitenet.net setup" $ props
[ "--repository=sftp://2318@usw-s002.rsync.net/~/git.kitenet.net"
, "--ssh-key=" ++ sshkey
, "--client-name=wren" -- historical
+ , Obnam.keepParam [Obnam.KeepDays 30]
] Obnam.OnlyClient (Gpg.GpgKeyId "1B169BE1")
`requires` Ssh.userKeyAt (Just sshkey)
(User "root")