]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added configuration
authorArvin Schnell <aschnell@suse.de>
Mon, 28 Feb 2011 13:38:41 +0000 (14:38 +0100)
committerArvin Schnell <aschnell@suse.de>
Mon, 28 Feb 2011 13:38:41 +0000 (14:38 +0100)
17 files changed:
data/sysconfig.snapper
scripts/snapper-daily
scripts/snapper-hourly
snapper/Factory.cc
snapper/Factory.h
snapper/Snapper.cc
snapper/Snapper.h
snapper/SnapperDefines.h
tools/.gitignore
tools/Makefile.am
tools/daily [new file with mode: 0755]
tools/daily.cc [deleted file]
tools/daily.o [new file with mode: 0644]
tools/hourly [new file with mode: 0755]
tools/hourly.cc [deleted file]
tools/hourly.o [new file with mode: 0644]
tools/snapper.cc

index e79e017b7ac9e34939b141d093002805b2a8a1ff..3b051147ff0431dfef555c240b6840b00a839877 100644 (file)
@@ -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=""
 
index dc7ed2b41c164d050e0e34fb93bd37bde15b1fa2..ff266dad1f298dea3d11f49c3ad7c857fd05d25c 100755 (executable)
@@ -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
index c31c1debc35a9fe893adee1026c35dae302d2004..0ec5c69e9af12039cfe18a8f04b0ef5640e74f3e 100755 (executable)
@@ -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
index 07674c0507bbda521f0f72de27e92aa28dadca38..3950f431311dfb6843f1b675440a9a814f4b3770 100644 (file)
@@ -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();
     }
 
index e5b12fef07d063ecafa6f92640ee713be4012104..00f4abf32f2fa9acf6159775e1dd3b4557df2a60 100644 (file)
@@ -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*);
 
index 736fb960201afccb50cb26a82410161366aa090e..a0becc55c03766ffdb279605538937c9abcc65af 100644 (file)
@@ -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);
 
index f31e4ca57fcafdd3fee7ff1f3bee12af7745e291..22c3b91d3ef54709e84e8b44ed9585ce527d82e9 100644 (file)
@@ -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<Snapshots::iterator>& tmp1);
 
-       const string subvolume;
+       const string config_name;
+
+       SysconfigFile* config;
+
+       string subvolume;
 
        Snapshots snapshots;
 
index 52c3de1854d425cb69103eb819c0889bc4191c29..611034b5d1d762339e44301e45b8026ef17fae35 100644 (file)
@@ -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"
index 0718d63e1c8234db40d9e51b9b682b44fc166717..311988651f6307147ffb07a54599b78d11e7bd3f 100644 (file)
@@ -2,7 +2,3 @@ compare-dirs.o
 compare-dirs
 snapper.o
 snapper
-hourly.o
-hourly
-daily.o
-daily
index b6e7c7b1124a15545fcf9f25713d7504c1c5598b..0db42e8edb4860f2510c9e6a497433c8c65eb4be 100644 (file)
@@ -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 (executable)
index 0000000..3574296
--- /dev/null
@@ -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 (file)
index 66ad07d..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-
-#include <stdlib.h>
-
-#include <snapper/AppUtil.h>
-#include <snapper/Snapper.h>
-#include <snapper/Factory.h>
-
-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 (file)
index 0000000..03ca956
Binary files /dev/null and b/tools/daily.o differ
diff --git a/tools/hourly b/tools/hourly
new file mode 100755 (executable)
index 0000000..fbe9d5e
--- /dev/null
@@ -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 (file)
index 40eced8..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-
-#include <stdlib.h>
-
-#include <snapper/AppUtil.h>
-#include <snapper/Snapper.h>
-#include <snapper/Factory.h>
-
-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 (file)
index 0000000..b84119f
Binary files /dev/null and b/tools/hourly.o differ
index a5d6ec7524682525f7db828d7f2c4fff0d880b17..e308042221c993a279bf764ba30eaef7db3900c3 100644 (file)
@@ -25,7 +25,7 @@ map<string, cmd_fnc> 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 <style>\tTable style (integer).") << endl
-        << _("\t--subvolume, -s <path>\t\tSet subvolume.") << endl
+        << _("\t--config, -c <name>\t\tSet name of config to use.") << endl
         << endl;
 
     help_list();
@@ -516,7 +516,7 @@ main(int argc, char** argv)
     const struct option options[] = {
        { "quiet",              no_argument,            0,      'q' },
        { "table-style",        required_argument,      0,      't' },
-       { "subvolume",          required_argument,      0,      's' },
+       { "config",             required_argument,      0,      'c' },
        { 0, 0, 0, 0 }
     };
 
@@ -557,10 +557,10 @@ main(int argc, char** argv)
        Table::defaultStyle = (TableLineStyle) s;
     }
 
-    if ((opt = opts.find("subvolume")) != opts.end())
-       subvolume = opt->second;
+    if ((opt = opts.find("config")) != opts.end())
+       config_name = opt->second;
 
-    sh = createSnapper(subvolume);
+    sh = createSnapper(config_name);
 
     if (!quiet)
        sh->setCompareCallback(&compare_callback_impl);