fillup_DATA = sysconfig.snapper
-EXTRA_DIST = $(fillup_DATA) snapper.logrotate example-config
+EXTRA_DIST = $(fillup_DATA) base.txt snapper.logrotate example-config
install-data-local:
install -D -m 644 snapper.logrotate $(DESTDIR)/etc/logrotate.d/snapper
install -d -m 755 $(DESTDIR)/etc/snapper/configs
+ install -d -m 755 $(DESTDIR)/etc/snapper/filters
+ install -D -m 644 base.txt $(DESTDIR)/etc/snapper/filters/base.txt
install -D -m 644 example-config $(DESTDIR)/usr/share/doc/packages/snapper/example-config
--- /dev/null
+/etc/mtab
+/etc/adjtime
+-------------------------------------------------------------------
+Mon Apr 04 14:20:43 CEST 2011 - aschnell@suse.de
+
+- allow to ignore files during snapshot comparison
+
-------------------------------------------------------------------
Mon Jan 10 14:55:25 CET 2011 - aschnell@suse.de
%{_libdir}/libsnapper.so.*
%dir %{_sysconfdir}/snapper
%dir %{_sysconfdir}/snapper/configs
+%dir %{_sysconfdir}/snapper/filters
+%config(noreplace) %{_sysconfdir}/snapper/filters/base.txt
%doc %dir %{prefix}/share/doc/packages/snapper
%doc %{prefix}/share/doc/packages/snapper/AUTHORS
%doc %{prefix}/share/doc/packages/snapper/COPYING
#include <sys/stat.h>
#include <sys/types.h>
-#include <glob.h>
#include <string.h>
#include <unistd.h>
+#include <fnmatch.h>
#include "snapper/File.h"
#include "snapper/Snapper.h"
}
+ struct FilterHelper
+ {
+ FilterHelper(const vector<string>& patterns)
+ : patterns(patterns) {}
+ bool operator()(const File& file)
+ {
+ for (vector<string>::const_iterator it = patterns.begin(); it != patterns.end(); ++it)
+ if (fnmatch(it->c_str(), file.getName().c_str(), 0) == 0)
+ return true;
+ return false;
+ }
+ const vector<string>& patterns;
+ };
+
+
+ void
+ Files::filter()
+ {
+ const vector<string>& filter_patterns = getSnapper()->getFilterPatterns();
+ entries.erase(remove_if(entries.begin(), entries.end(), FilterHelper(filter_patterns)),
+ entries.end());
+ }
+
+
void
Files::initialize()
{
save();
}
}
+
+ filter();
}
void create();
bool load();
bool save();
+ void filter();
RollbackStatistic getRollbackStatistic() const;
y2mil("subvolume:" << subvolume);
+ loadPatterns();
+
snapshots.initialize();
}
}
+ void
+ Snapper::loadPatterns()
+ {
+ const list<string> files = glob(FILTERSDIR "/*.txt", GLOB_NOSORT);
+ for (list<string>::const_iterator it = files.begin(); it != files.end(); ++it)
+ {
+ FILE* file = fopen(it->c_str(), "r");
+ if (file == NULL)
+ {
+ y2err("file not found");
+ continue;
+ }
+
+ char* line = NULL;
+ size_t len = 0;
+
+ while (getline(&line, &len, file) != -1)
+ {
+ // TODO: more robust
+
+ string filter_pattern = string(line, 0, strlen(line) - 1);
+
+ filter_patterns.push_back(filter_pattern);
+ }
+
+ free(line);
+
+ fclose(file);
+ }
+
+ y2mil("number of filter patterns:" << filter_patterns.size());
+ }
+
+
// Directory of which snapshots are made, e.g. "/" or "/home".
string
Snapper::subvolumeDir() const
#define SNAPPER_H
+#include <vector>
+
#include "snapper/Snapshot.h"
namespace snapper
{
+ using std::vector;
+
+
class SysconfigFile;
void setCompareCallback(CompareCallback* p) { compare_callback = p; }
CompareCallback* getCompareCallback() const { return compare_callback; }
+ const vector<string>& getFilterPatterns() const { return filter_patterns; }
+
private:
void filter1(list<Snapshots::iterator>& tmp, time_t min_age);
void filter2(list<Snapshots::iterator>& tmp);
+ void loadPatterns();
+
const string config_name;
SysconfigFile* config;
string subvolume;
+ vector<string> filter_patterns;
+
Snapshots snapshots;
CompareCallback* compare_callback;
#define CONFIGSDIR "/etc/snapper/configs"
+#define FILTERSDIR "/etc/snapper/filters"
#define SNAPSHOTDIR "/snapshot"
#define SNAPSHOTSDIR "/snapshots"