]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- min age for snapshots for cleanup
authorArvin Schnell <aschnell@suse.de>
Fri, 4 Mar 2011 14:00:31 +0000 (15:00 +0100)
committerArvin Schnell <aschnell@suse.de>
Fri, 4 Mar 2011 14:00:31 +0000 (15:00 +0100)
data/example-config
snapper/Snapper.cc
snapper/Snapper.h

index 95aa3d6709542f1b06a05cfa2cf214b315fb4d10..ee6c2f56d2e4a26837dfed5a6970f3f87b0a0976 100644 (file)
@@ -7,6 +7,7 @@ SUBVOLUME="/"
 NUMBER_CLEANUP="yes"
 
 # limit for number cleanup
+NUMBER_MIN_AGE="1800"
 NUMBER_LIMIT="100"
 
 
@@ -17,12 +18,16 @@ TIMELINE_CREATE="yes"
 TIMELINE_CLEANUP="yes"
 
 # limits for timeline cleanup
+TIMELINE_MIN_AGE="1800"
 TIMELINE_LIMIT_HOURLY="10"
 TIMELINE_LIMIT_DAILY="10"
 TIMELINE_LIMIT_MONTHLY="10"
 TIMELINE_LIMIT_YEARLY="10"
 
 
-# cleanup empty pre post pairs
+# cleanup empty pre-post-pairs
 EMPTY_PRE_POST_CLEANUP="yes"
 
+# limits for empty pre-post-pair cleanup
+EMPTY_PRE_POST_MIN_AGE="1800"
+
index cec2318594a87b6ed67f965264bdfb1bd20fb0d3..7de9f0cbb0985c33bf9e88b3e586d18e447675d8 100644 (file)
@@ -154,21 +154,39 @@ namespace snapper
     }
 
 
+    struct younger_than
+    {
+       younger_than(time_t t)
+           : t(t) {}
+       bool operator()(Snapshots::const_iterator it)
+           { return it->getDate() > t; }
+       const time_t t;
+    };
+
+
+    // Removes snapshots younger than min_age from tmp
+    void
+    Snapper::filter1(list<Snapshots::iterator>& tmp, time_t min_age)
+    {
+       tmp.remove_if(younger_than(time(NULL) - min_age));
+    }
+
+
     // Removes pre and post snapshots from tmp that do have a corresponding
     // snapshot but which is not included in tmp.
     void
-    Snapper::filter1(list<Snapshots::iterator>& tmp1)
+    Snapper::filter2(list<Snapshots::iterator>& tmp)
     {
        list<Snapshots::iterator> ret;
 
-       for (list<Snapshots::iterator>::const_iterator it1 = tmp1.begin(); it1 != tmp1.end(); ++it1)
+       for (list<Snapshots::iterator>::const_iterator it1 = tmp.begin(); it1 != tmp.end(); ++it1)
        {
            if ((*it1)->getType() == PRE)
            {
                Snapshots::const_iterator it2 = snapshots.findPost(*it1);
                if (it2 != snapshots.end())
                {
-                   if (find(tmp1.begin(), tmp1.end(), it2) == tmp1.end())
+                   if (find(tmp.begin(), tmp.end(), it2) == tmp.end())
                        continue;
                }
            }
@@ -178,7 +196,7 @@ namespace snapper
                Snapshots::const_iterator it2 = snapshots.findPre(*it1);
                if (it2 != snapshots.end())
                {
-                   if (find(tmp1.begin(), tmp1.end(), it2) == tmp1.end())
+                   if (find(tmp.begin(), tmp.end(), it2) == tmp.end())
                        continue;
                }
            }
@@ -186,20 +204,23 @@ namespace snapper
            ret.push_back(*it1);
        }
 
-       swap(ret, tmp1);
+       swap(ret, tmp);
     }
 
 
     bool
     Snapper::doCleanupNumber()
     {
+       time_t min_age = 1800;
        size_t limit = 50;
 
        string val;
+       if (config->getValue("NUMBER_MIN_AGE", val))
+           val >> min_age;
        if (config->getValue("NUMBER_LIMIT", val))
            val >> limit;
 
-       y2mil("limit:" << limit);
+       y2mil("min_age:" << min_age << " limit:" << limit);
 
        list<Snapshots::iterator> tmp;
 
@@ -215,7 +236,8 @@ namespace snapper
            advance(it, - limit);
            tmp.erase(it, tmp.end());
 
-           filter1(tmp);
+           filter1(tmp, min_age);
+           filter2(tmp);
 
            y2mil("deleting " << tmp.size() << " snapshots");
 
@@ -318,12 +340,15 @@ namespace snapper
     bool
     Snapper::doCleanupTimeline()
     {
+       time_t min_age = 1800;
        size_t limit_hourly = 10;
        size_t limit_daily = 10;
        size_t limit_monthly = 10;
        size_t limit_yearly = 10;
 
        string val;
+       if (config->getValue("TIMELINE_MIN_AGE", val))
+           val >> min_age;
        if (config->getValue("TIMELINE_LIMIT_HOURLY", val))
            val >> limit_hourly;
        if (config->getValue("TIMELINE_LIMIT_DAILY", val))
@@ -333,8 +358,9 @@ namespace snapper
        if (config->getValue("TIMELINE_LIMIT_YEARLY", val))
            val >> limit_yearly;
 
-       y2mil("limit_hourly:" << limit_hourly << " limit_daily:" << limit_daily <<
-             " limit_monthly:" << limit_monthly << " limit_yearly:" << limit_yearly);
+       y2mil("min_age:" << min_age <<" limit_hourly:" << limit_hourly << " limit_daily:" <<
+             limit_daily << " limit_monthly:" << limit_monthly << " limit_yearly:" <<
+             limit_yearly);
 
        size_t num_hourly = 0;
        size_t num_daily = 0;
@@ -380,7 +406,8 @@ namespace snapper
 
        tmp.reverse();
 
-       filter1(tmp);
+       filter1(tmp, min_age);
+       filter2(tmp);
 
        y2mil("deleting " << tmp.size() << " snapshots");
 
@@ -394,6 +421,14 @@ namespace snapper
     bool
     Snapper::doCleanupEmptyPrePost()
     {
+       time_t min_age = 1800;
+
+       string val;
+       if (config->getValue("EMPTY_PRE_POST_MIN_AGE", val))
+           val >> min_age;
+
+       y2mil("min_age:" << min_age);
+
        list<Snapshots::iterator> tmp;
 
        for (Snapshots::iterator it1 = snapshots.begin(); it1 != snapshots.end(); ++it1)
@@ -414,6 +449,9 @@ namespace snapper
            }
        }
 
+       filter1(tmp, min_age);
+       filter2(tmp);
+
        y2mil("deleting " << tmp.size() << " snapshots");
 
        for (list<Snapshots::iterator>::iterator it = tmp.begin(); it != tmp.end(); ++it)
index d4fbc98ab2d5e691ffc3b0393cd8810b82b88a16..4b169c771d354444662e23de7bc46fe2b1307083 100644 (file)
@@ -75,7 +75,8 @@ namespace snapper
 
     private:
 
-       void filter1(list<Snapshots::iterator>& tmp1);
+       void filter1(list<Snapshots::iterator>& tmp, time_t min_age);
+       void filter2(list<Snapshots::iterator>& tmp);
 
        const string config_name;