From: Arvin Schnell Date: Fri, 4 Mar 2011 14:00:31 +0000 (+0100) Subject: - min age for snapshots for cleanup X-Git-Tag: v0.1.3~432 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c8f907442b73090cfb19a7d04b8cfc3173add87;p=thirdparty%2Fsnapper.git - min age for snapshots for cleanup --- diff --git a/data/example-config b/data/example-config index 95aa3d67..ee6c2f56 100644 --- a/data/example-config +++ b/data/example-config @@ -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" + diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index cec23185..7de9f0cb 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -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& 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& tmp1) + Snapper::filter2(list& tmp) { list ret; - for (list::const_iterator it1 = tmp1.begin(); it1 != tmp1.end(); ++it1) + for (list::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 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 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::iterator it = tmp.begin(); it != tmp.end(); ++it) diff --git a/snapper/Snapper.h b/snapper/Snapper.h index d4fbc98a..4b169c77 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -75,7 +75,8 @@ namespace snapper private: - void filter1(list& tmp1); + void filter1(list& tmp, time_t min_age); + void filter2(list& tmp); const string config_name;