]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- extended number cleanup algorithm to privilege important snapshots (fate#316233)
authorArvin Schnell <aschnell@suse.de>
Thu, 17 Oct 2013 08:21:22 +0000 (10:21 +0200)
committerArvin Schnell <aschnell@suse.de>
Thu, 17 Oct 2013 08:21:22 +0000 (10:21 +0200)
client/cleanup.cc
data/default-config
doc/snapper-configs.xml.in
package/snapper.changes

index 285631d7d0e0fb6cf75f988fedfac2a061bffffc..875fe796f322839926f4890260f40c27424f89c1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2011-2012] Novell, Inc.
+ * Copyright (c) [2011-2013] Novell, Inc.
  *
  * All Rights Reserved.
  *
@@ -83,11 +83,20 @@ filter2(const XSnapshots& snapshots, list<XSnapshots::const_iterator>& tmp)
 }
 
 
+bool
+is_important(XSnapshots::const_iterator it1)
+{
+    map<string, string>::const_iterator it2 = it1->getUserdata().find("important");
+    return it2 != it1->getUserdata().end() && it2->second == "yes";
+}
+
+
 bool
 do_cleanup_number(DBus::Connection& conn, const string& config_name)
 {
     time_t min_age = 1800;
     size_t limit = 50;
+    size_t limit_important = 10;
 
     XConfigInfo ci = command_get_xconfig(conn, config_name);
     map<string, string>::const_iterator pos;
@@ -95,6 +104,11 @@ do_cleanup_number(DBus::Connection& conn, const string& config_name)
        pos->second >> min_age;
     if ((pos = ci.raw.find("NUMBER_LIMIT")) != ci.raw.end())
        pos->second >> limit;
+    if ((pos = ci.raw.find("NUMBER_LIMIT_IMPORTANT")) != ci.raw.end())
+       pos->second >> limit_important;
+
+    size_t num = 0;
+    size_t num_important = 0;
 
     XSnapshots snapshots = command_list_xsnapshots(conn, config_name);
 
@@ -103,24 +117,41 @@ do_cleanup_number(DBus::Connection& conn, const string& config_name)
     for (XSnapshots::const_iterator it = snapshots.begin(); it != snapshots.end(); ++it)
     {
        if (it->getCleanup() == "number")
-           tmp.push_back(it);
+           tmp.push_front(it);
     }
 
-    if (tmp.size() > limit)
+    list<XSnapshots::const_iterator>::iterator it = tmp.begin();
+    while (it != tmp.end())
     {
-       list<XSnapshots::const_iterator>::iterator it = tmp.end();
-       advance(it, - limit);
-       tmp.erase(it, tmp.end());
-
-       filter1(tmp, min_age);
-       filter2(snapshots, tmp);
+       bool keep = false;
 
-       for (list<XSnapshots::const_iterator>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
+       if (num_important < limit_important && is_important(*it))
        {
-           list<unsigned int> nums;
-           nums.push_back((*it)->getNum());
-           command_delete_xsnapshots(conn, config_name, nums);
+           ++num_important;
+           keep = true;
        }
+       if (num < limit)
+       {
+           ++num;
+           keep = true;
+       }
+
+       if (keep)
+           it = tmp.erase(it);
+       else
+           ++it;
+    }
+
+    tmp.reverse();
+
+    filter1(tmp, min_age);
+    filter2(snapshots, tmp);
+
+    for (list<XSnapshots::const_iterator>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
+    {
+       list<unsigned int> nums;
+       nums.push_back((*it)->getNum());
+       command_delete_xsnapshots(conn, config_name, nums);
     }
 
     return true;
@@ -279,13 +310,9 @@ do_cleanup_timeline(DBus::Connection& conn, const string& config_name)
        }
 
        if (keep)
-       {
            it = tmp.erase(it);
-       }
        else
-       {
            ++it;
-       }
     }
 
     tmp.reverse();
index 0b65c08711880871da5e0c2154de7d66ed1a7e9a..71c80c8d4ebebf728d10bd698ef401fa58177a6d 100644 (file)
@@ -20,6 +20,7 @@ NUMBER_CLEANUP="yes"
 # limit for number cleanup
 NUMBER_MIN_AGE="1800"
 NUMBER_LIMIT="50"
+NUMBER_LIMIT_IMPORTANT="10"
 
 
 # create hourly snapshots
index c75393e36367e864f05fcdc0ce030ee3d682f666..abceffe289203f82810b4538e86532ced406ffac 100644 (file)
        </listitem>
       </varlistentry>
 
+      <varlistentry>
+       <term><option>NUMBER_LIMIT_IMPORTANT=<replaceable>number</replaceable></option></term>
+       <listitem>
+         <para>Defines how many important snapshots the number cleanup
+         algorithm should keep. Important snapshots have important=yes in the
+         userdata. The youngest important snapshots will be kept.</para>
+         <para>Default value is &quot;10&quot;.</para>
+         <para>New in version 0.1.8.</para>
+       </listitem>
+      </varlistentry>
+
       <varlistentry>
        <term><option>TIMELINE_CREATE=<replaceable>boolean</replaceable></option></term>
        <listitem>
index 8f73313ffcd4987d73c6d0dda856d400fc35be53..2c2e59df17a17fdf9027def343cfe2dd7f8afb68 100644 (file)
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+Thu Oct 17 10:17:59 CEST 2013 - aschnell@suse.de
+
+- extended number cleanup algorithm to privilege important
+  snapshots (fate#316233)
+
 -------------------------------------------------------------------
 Tue Oct 15 16:28:15 CEST 2013 - aschnell@suse.de