From: Arvin Schnell Date: Mon, 28 Feb 2011 13:38:41 +0000 (+0100) Subject: - added configuration X-Git-Tag: v0.1.3~453 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d59e6c7278569860c7b4d6608d5ab0dc3e9e0e2e;p=thirdparty%2Fsnapper.git - added configuration --- diff --git a/data/sysconfig.snapper b/data/sysconfig.snapper index e79e017b..3b051147 100644 --- a/data/sysconfig.snapper +++ b/data/sysconfig.snapper @@ -1,12 +1,7 @@ ## Path: System/Yast2/Snapper -## Type: yesno -## Default: no -# Enable snapper. -ENABLE_SNAPPER="no" - ## Type: string -## Default: "/" +## Default: "" # Directories for which snapper ... -SNAPPER_SUBVOLUMES="/" +SNAPPER_CONFIGS="" diff --git a/scripts/snapper-daily b/scripts/snapper-daily index dc7ed2b4..ff266dad 100755 --- a/scripts/snapper-daily +++ b/scripts/snapper-daily @@ -7,6 +7,7 @@ umask 022 PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH + # # get information from /etc/sysconfig # @@ -14,11 +15,25 @@ if [ -f /etc/sysconfig/snapper ] ; then . /etc/sysconfig/snapper fi + # -# run special program for every subvolume +# run snapper for all configs # -for subvolume in $SNAPPER_SUBVOLUMES ; do - /usr/lib/snapper/bin/daily $subvolume +for CONFIG in $CONFIGS ; do + + NUMBER_CLEANUP="no" + TIMELINE_CLEANUP="no" + + . /etc/sysconfig/snapper.d/$CONFIG + + if [ "$NUMBER_CLEANUP" = "yes" ] ; then + snapper --config=$CONFIG cleanup number + fi + + if [ "$TIMELINE_CLEANUP" = "yes" ] ; then + snapper --config=$CONFIG cleanup timeline + fi + done exit 0 diff --git a/scripts/snapper-hourly b/scripts/snapper-hourly index c31c1deb..0ec5c69e 100755 --- a/scripts/snapper-hourly +++ b/scripts/snapper-hourly @@ -7,6 +7,7 @@ umask 022 PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH + # # get information from /etc/sysconfig # @@ -14,11 +15,20 @@ if [ -f /etc/sysconfig/snapper ] ; then . /etc/sysconfig/snapper fi + # -# run special program for every subvolume +# run snapper for all configs # -for subvolume in $SNAPPER_SUBVOLUMES ; do - /usr/lib/snapper/bin/hourly $subvolume +for CONFIG in $CONFIGS ; do + + TIMELINE_CREATE="no" + + . /etc/sysconfig/snapper.d/$CONFIG + + if [ "$TIMELINE_CREATE" = "yes" ] ; then + snapper --config=$CONFIG create --description="timeline" --cleanup="timeline" + fi + done exit 0 diff --git a/snapper/Factory.cc b/snapper/Factory.cc index 07674c05..3950f431 100644 --- a/snapper/Factory.cc +++ b/snapper/Factory.cc @@ -33,10 +33,10 @@ namespace snapper Snapper* - createSnapper(const string& subvolume) + createSnapper(const string& config_name) { assert(!haha.get()); - haha.reset(new Snapper(subvolume)); + haha.reset(new Snapper(config_name)); return haha.get(); } diff --git a/snapper/Factory.h b/snapper/Factory.h index e5b12fef..00f4abf3 100644 --- a/snapper/Factory.h +++ b/snapper/Factory.h @@ -37,7 +37,7 @@ namespace snapper // Only one Snapper can be created at a time. - Snapper* createSnapper(const string& subvolume = "/"); + Snapper* createSnapper(const string& config_name = "root"); void deleteSnapper(Snapper*); diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 736fb960..a0becc55 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -34,6 +34,7 @@ #include "snapper/SystemCmd.h" #include "snapper/SnapperDefines.h" #include "snapper/File.h" +#include "snapper/AsciiFile.h" namespace snapper @@ -41,11 +42,20 @@ namespace snapper using namespace std; - Snapper::Snapper(const string& subvolume) - : subvolume(subvolume), snapshots(this), files(this), compare_callback(NULL) + Snapper::Snapper(const string& config_name) + : config_name(config_name), config(NULL), subvolume("/"), snapshots(this), files(this), + compare_callback(NULL) { y2mil("Snapper constructor"); y2mil("libsnapper version " VERSION); + y2mil("config_name:" << config_name); + + config = new SysconfigFile((CONFIGDIR "/" + config_name).c_str()); + + string val; + if (config->getValue("SUBVOLUME", val)) + subvolume = val; + y2mil("subvolume:" << subvolume); snapshots.initialize(); @@ -55,6 +65,8 @@ namespace snapper Snapper::~Snapper() { y2mil("Snapper destructor"); + + delete config; } @@ -211,7 +223,11 @@ namespace snapper bool Snapper::doCleanupNumber() { - size_t limit = 50; // TODO + size_t limit = 50; + + string val; + if (config->getValue("NUMBER_LIMIT", val)) + val >> limit; y2mil("limit:" << limit); diff --git a/snapper/Snapper.h b/snapper/Snapper.h index f31e4ca5..22c3b91d 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -30,6 +30,8 @@ namespace snapper { + class SysconfigFile; + struct CompareCallback { @@ -45,7 +47,7 @@ namespace snapper { public: - Snapper(const string& subvolume = "/"); + Snapper(const string& config_name = "root"); ~Snapper(); string subvolumeDir() const; @@ -88,7 +90,11 @@ namespace snapper void filter1(vector& tmp1); - const string subvolume; + const string config_name; + + SysconfigFile* config; + + string subvolume; Snapshots snapshots; diff --git a/snapper/SnapperDefines.h b/snapper/SnapperDefines.h index 52c3de18..611034b5 100644 --- a/snapper/SnapperDefines.h +++ b/snapper/SnapperDefines.h @@ -24,7 +24,7 @@ #define SNAPPER_DEFINES_H -#define SYSCONFIGFILE "/etc/sysconfig/snapper" +#define CONFIGDIR "/etc/sysconfig/snapper.d" #define SNAPSHOTDIR "/snapshot" #define SNAPSHOTSDIR "/snapshots" diff --git a/tools/.gitignore b/tools/.gitignore index 0718d63e..31198865 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -2,7 +2,3 @@ compare-dirs.o compare-dirs snapper.o snapper -hourly.o -hourly -daily.o -daily diff --git a/tools/Makefile.am b/tools/Makefile.am index b6e7c7b1..0db42e8e 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -9,17 +9,11 @@ INCLUDES = -I$(top_srcdir) toolsbindir = /usr/lib/snapper/bin -toolsbin_PROGRAMS = compare-dirs hourly daily +toolsbin_PROGRAMS = compare-dirs compare_dirs_SOURCES = compare-dirs.cc compare_dirs_LDADD = ../snapper/libsnapper.la -hourly_SOURCES = hourly.cc -hourly_LDADD = ../snapper/libsnapper.la - -daily_SOURCES = daily.cc -daily_LDADD = ../snapper/libsnapper.la - bin_PROGRAMS = snapper diff --git a/tools/daily b/tools/daily new file mode 100755 index 00000000..35742964 --- /dev/null +++ b/tools/daily @@ -0,0 +1,130 @@ +#! /bin/sh + +# daily - temporary wrapper script for .libs/daily +# Generated by ltmain.sh (GNU libtool) 2.2.6b +# +# The daily program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +Xsed='/usr/bin/sed -e 1s/^X//' +sed_quote_subst='s/\([`"$\\]\)/\\\1/g' + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command="" + +# This environment variable determines our operation mode. +if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then + # install mode needs the following variables: + generated_by_libtool_version='2.2.6b' + notinst_deplibs=' ../snapper/libsnapper.la' +else + # When we are sourced in execute mode, $file and $ECHO are already set. + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + ECHO="echo" + file="$0" + # Make sure echo works. + if test "X$1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift + elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then + # Yippee, $ECHO works! + : + else + # Restart under the correct shell, and then maybe $ECHO will work. + exec /bin/sh "$0" --no-reexec ${1+"$@"} + fi + fi + + # Find the directory that this script lives in. + thisdir=`$ECHO "X$file" | $Xsed -e 's%/[^/]*$%%'` + test "x$thisdir" = "x$file" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=`ls -ld "$file" | /usr/bin/sed -n 's/.*-> //p'` + while test -n "$file"; do + destdir=`$ECHO "X$file" | $Xsed -e 's%/[^/]*$%%'` + + # If there was a directory component, then change thisdir. + if test "x$destdir" != "x$file"; then + case "$destdir" in + [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; + *) thisdir="$thisdir/$destdir" ;; + esac + fi + + file=`$ECHO "X$file" | $Xsed -e 's%^.*/%%'` + file=`ls -ld "$thisdir/$file" | /usr/bin/sed -n 's/.*-> //p'` + done + + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no + if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then + # special case for '.' + if test "$thisdir" = "."; then + thisdir=`pwd` + fi + # remove .libs from thisdir + case "$thisdir" in + *[\\/].libs ) thisdir=`$ECHO "X$thisdir" | $Xsed -e 's%[\\/][^\\/]*$%%'` ;; + .libs ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=`cd "$thisdir" && pwd` + test -n "$absdir" && thisdir="$absdir" + + program='daily' + progdir="$thisdir/.libs" + + + if test -f "$progdir/$program"; then + # Add our own library path to LD_LIBRARY_PATH + LD_LIBRARY_PATH="/ARVIN/snapper/snapper/.libs:/usr/lib:$LD_LIBRARY_PATH" + + # Some systems cannot cope with colon-terminated LD_LIBRARY_PATH + # The second colon is a workaround for a bug in BeOS R4 sed + LD_LIBRARY_PATH=`$ECHO "X$LD_LIBRARY_PATH" | $Xsed -e 's/::*$//'` + + export LD_LIBRARY_PATH + + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + # Run the actual program with our arguments. + + exec "$progdir/$program" ${1+"$@"} + + $ECHO "$0: cannot exec $program $*" 1>&2 + exit 1 + fi + else + # The program doesn't exist. + $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 + $ECHO "This script is just a wrapper for $program." 1>&2 + echo "See the libtool documentation for more information." 1>&2 + exit 1 + fi +fi diff --git a/tools/daily.cc b/tools/daily.cc deleted file mode 100644 index 66ad07d5..00000000 --- a/tools/daily.cc +++ /dev/null @@ -1,34 +0,0 @@ - -#include - -#include -#include -#include - -using namespace snapper; - - -int -main(int argc, char** argv) -{ - if (argc != 2) - { - fprintf(stderr, "usage: daily subvolume\n"); - exit(EXIT_FAILURE); - } - - initDefaultLogger(); - - string subvolume = argv[1]; - - y2mil("daily subvolume:" << subvolume); - - Snapper* sh = createSnapper(subvolume); - - sh->doCleanupNumber(); - sh->doCleanupTimeline(); - - deleteSnapper(sh); - - exit(EXIT_SUCCESS); -} diff --git a/tools/daily.o b/tools/daily.o new file mode 100644 index 00000000..03ca9567 Binary files /dev/null and b/tools/daily.o differ diff --git a/tools/hourly b/tools/hourly new file mode 100755 index 00000000..fbe9d5ef --- /dev/null +++ b/tools/hourly @@ -0,0 +1,130 @@ +#! /bin/sh + +# hourly - temporary wrapper script for .libs/hourly +# Generated by ltmain.sh (GNU libtool) 2.2.6b +# +# The hourly program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +Xsed='/usr/bin/sed -e 1s/^X//' +sed_quote_subst='s/\([`"$\\]\)/\\\1/g' + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command="" + +# This environment variable determines our operation mode. +if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then + # install mode needs the following variables: + generated_by_libtool_version='2.2.6b' + notinst_deplibs=' ../snapper/libsnapper.la' +else + # When we are sourced in execute mode, $file and $ECHO are already set. + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + ECHO="echo" + file="$0" + # Make sure echo works. + if test "X$1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift + elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then + # Yippee, $ECHO works! + : + else + # Restart under the correct shell, and then maybe $ECHO will work. + exec /bin/sh "$0" --no-reexec ${1+"$@"} + fi + fi + + # Find the directory that this script lives in. + thisdir=`$ECHO "X$file" | $Xsed -e 's%/[^/]*$%%'` + test "x$thisdir" = "x$file" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=`ls -ld "$file" | /usr/bin/sed -n 's/.*-> //p'` + while test -n "$file"; do + destdir=`$ECHO "X$file" | $Xsed -e 's%/[^/]*$%%'` + + # If there was a directory component, then change thisdir. + if test "x$destdir" != "x$file"; then + case "$destdir" in + [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; + *) thisdir="$thisdir/$destdir" ;; + esac + fi + + file=`$ECHO "X$file" | $Xsed -e 's%^.*/%%'` + file=`ls -ld "$thisdir/$file" | /usr/bin/sed -n 's/.*-> //p'` + done + + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no + if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then + # special case for '.' + if test "$thisdir" = "."; then + thisdir=`pwd` + fi + # remove .libs from thisdir + case "$thisdir" in + *[\\/].libs ) thisdir=`$ECHO "X$thisdir" | $Xsed -e 's%[\\/][^\\/]*$%%'` ;; + .libs ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=`cd "$thisdir" && pwd` + test -n "$absdir" && thisdir="$absdir" + + program='hourly' + progdir="$thisdir/.libs" + + + if test -f "$progdir/$program"; then + # Add our own library path to LD_LIBRARY_PATH + LD_LIBRARY_PATH="/ARVIN/snapper/snapper/.libs:/usr/lib:$LD_LIBRARY_PATH" + + # Some systems cannot cope with colon-terminated LD_LIBRARY_PATH + # The second colon is a workaround for a bug in BeOS R4 sed + LD_LIBRARY_PATH=`$ECHO "X$LD_LIBRARY_PATH" | $Xsed -e 's/::*$//'` + + export LD_LIBRARY_PATH + + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + # Run the actual program with our arguments. + + exec "$progdir/$program" ${1+"$@"} + + $ECHO "$0: cannot exec $program $*" 1>&2 + exit 1 + fi + else + # The program doesn't exist. + $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 + $ECHO "This script is just a wrapper for $program." 1>&2 + echo "See the libtool documentation for more information." 1>&2 + exit 1 + fi +fi diff --git a/tools/hourly.cc b/tools/hourly.cc deleted file mode 100644 index 40eced89..00000000 --- a/tools/hourly.cc +++ /dev/null @@ -1,37 +0,0 @@ - -#include - -#include -#include -#include - -using namespace snapper; - - -int -main(int argc, char** argv) -{ - if (argc != 2) - { - fprintf(stderr, "usage: hourly subvolume\n"); - exit(EXIT_FAILURE); - } - - initDefaultLogger(); - - string subvolume = argv[1]; - - y2mil("hourly subvolume:" << subvolume); - - if (subvolume != "/") // TODO - exit(EXIT_SUCCESS); - - Snapper* sh = createSnapper(subvolume); - - Snapshots::iterator snap = sh->createSingleSnapshot("timeline"); - snap->setCleanup("timeline"); - - deleteSnapper(sh); - - exit(EXIT_SUCCESS); -} diff --git a/tools/hourly.o b/tools/hourly.o new file mode 100644 index 00000000..b84119f7 Binary files /dev/null and b/tools/hourly.o differ diff --git a/tools/snapper.cc b/tools/snapper.cc index a5d6ec75..e3080422 100644 --- a/tools/snapper.cc +++ b/tools/snapper.cc @@ -25,7 +25,7 @@ map cmds; GetOpts getopts; bool quiet = false; -string subvolume = "/"; +string config_name = "root"; Snapper* sh = NULL; @@ -475,7 +475,7 @@ command_help() cout << _(" Global options:") << endl << _("\t--quiet, -q\t\t\tSuppress normal output.") << endl << _("\t--table-style, -t