From: Arvin Schnell Date: Thu, 17 Oct 2013 08:21:22 +0000 (+0200) Subject: - extended number cleanup algorithm to privilege important snapshots (fate#316233) X-Git-Tag: v0.1.8~23 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=ea4dfd1935a24b29172d04cec1a9360209fb5726;p=thirdparty%2Fsnapper.git - extended number cleanup algorithm to privilege important snapshots (fate#316233) --- diff --git a/client/cleanup.cc b/client/cleanup.cc index 285631d7..875fe796 100644 --- a/client/cleanup.cc +++ b/client/cleanup.cc @@ -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& tmp) } +bool +is_important(XSnapshots::const_iterator it1) +{ + map::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::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::iterator it = tmp.begin(); + while (it != tmp.end()) { - list::iterator it = tmp.end(); - advance(it, - limit); - tmp.erase(it, tmp.end()); - - filter1(tmp, min_age); - filter2(snapshots, tmp); + bool keep = false; - for (list::const_iterator it = tmp.begin(); it != tmp.end(); ++it) + if (num_important < limit_important && is_important(*it)) { - list 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::const_iterator it = tmp.begin(); it != tmp.end(); ++it) + { + list 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(); diff --git a/data/default-config b/data/default-config index 0b65c087..71c80c8d 100644 --- a/data/default-config +++ b/data/default-config @@ -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 diff --git a/doc/snapper-configs.xml.in b/doc/snapper-configs.xml.in index c75393e3..abceffe2 100644 --- a/doc/snapper-configs.xml.in +++ b/doc/snapper-configs.xml.in @@ -108,6 +108,17 @@ + + + + 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. + Default value is "10". + New in version 0.1.8. + + + diff --git a/package/snapper.changes b/package/snapper.changes index 8f73313f..2c2e59df 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -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