From 4e89e3343708f417ee8a1459be71688a5c85a3fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20de=20Saint=20Martin?= <cedric.dsm@tiolive.com>
Date: Mon, 30 Sep 2013 13:44:05 +0200
Subject: [PATCH] Resiliency: Only keep 10 increments of backup.

Also allow to bypass default value.
---
 slapos/recipe/pbs.py                       | 5 +++++
 stack/resilient/buildout.cfg               | 2 +-
 stack/resilient/template-replicated.cfg.in | 3 ++-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/slapos/recipe/pbs.py b/slapos/recipe/pbs.py
index 451321fb4..fa7253bfd 100644
--- a/slapos/recipe/pbs.py
+++ b/slapos/recipe/pbs.py
@@ -169,6 +169,9 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
                   # XXX: bang
                   mv %(local_directory)s %(local_directory)s.$(date +%%s)
               fi
+          else
+              # Everything's okay, cleaning up...
+              $RDIFF_BACKUP --remove-older-than %(remove_backup_older_than)s --force %(local_directory)s
           fi
           """)
       rdiff_wrapper_content = rdiff_wrapper_template % {
@@ -176,6 +179,8 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
               'rdiffbackup_binary': self.options['rdiffbackup-binary'],
               'local_directory': local_directory,
               'rdiffbackup_parameter': ' \\\n    '.join(rdiffbackup_parameter_list),
+              # XXX: only 10 increments is not enough by default.
+              'remove_backup_older_than': entry.get('remove-backup-older-than', '3B')
       }
       rdiff_wrapper = self.createFile(
           name=rdiff_wrapper_path,
diff --git a/stack/resilient/buildout.cfg b/stack/resilient/buildout.cfg
index 9018fa5de..8bbb7d45e 100644
--- a/stack/resilient/buildout.cfg
+++ b/stack/resilient/buildout.cfg
@@ -61,7 +61,7 @@ mode = 0644
 [template-replicated]
 recipe = slapos.recipe.download
 url = ${:_profile_base_location_}/template-replicated.cfg.in
-md5sum = e1ea317ad93c1bfaf0b82f5b0b4670c2
+md5sum = c762a625f65193bc8a570b4d56a0d08c
 mode = 0644
 destination = ${buildout:directory}/template-replicated.cfg.in
 
diff --git a/stack/resilient/template-replicated.cfg.in b/stack/resilient/template-replicated.cfg.in
index bc87fb24b..e977505c1 100644
--- a/stack/resilient/template-replicated.cfg.in
+++ b/stack/resilient/template-replicated.cfg.in
@@ -171,7 +171,7 @@ sla-{{ key }} = {{ value }}
 [request-pull-backup-server-{{namebase}}-{{id}}]
 <= request-pbs-common
 name = PBS {{id}} pulling from ${request-{{namebase}}:name}
-config = url name type server-key on-notification notify notification-id title
+config = url name type server-key on-notification notify notification-id title remove-backup-older-than
 config-url = ${request-{{namebase}}:connection-ssh-url}
 config-type = pull
 config-server-key = ${request-{{namebase}}:connection-ssh-public-key}
@@ -180,6 +180,7 @@ config-notify = ${request-pbs-{{namebase}}-{{id}}:connection-notification-url}
 config-notification-id = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}-pull
 config-name = ${slap-connection:computer-id}-${slap-connection:partition-id}-{{namebase}}-{{id}}
 config-title = Pulling from {{namebase}}
+config-remove-backup-older-than = {{ slapparameter_dict.get('remove-backup-older-than', '3B') }}
 slave = true
 sla = instance_guid
 sla-instance_guid = ${request-pbs-{{namebase}}-{{id}}:instance_guid}
-- 
2.30.9