live-snapshot: now supports a static keep file list.
authorMarco Amadori <marco.amadori@gmail.com>
Fri, 6 Jun 2008 21:44:09 +0000 (23:44 +0200)
committerDaniel Baumann <daniel@debian.org>
Wed, 9 Mar 2011 16:48:00 +0000 (17:48 +0100)
* Included support for specifing a list of files/dirs to be explicitly
  kept between reboots, enabled only for the "cpio" snapshot type.
  Look at "/usr/share/doc/live-initramfs/examples/live-snapshot.list"
  for hints.

Makefile
bin/live-snapshot
conf/live-snapshot.list [new file with mode: 0644]
manpages/live-snapshot.en.1.txt
manpages/live-snapshot.it.1.txt
scripts/live

index 30af16d..ed1af45 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -40,7 +40,7 @@ install: test build
        cp -r COPYING docs/* $(DESTDIR)/usr/share/doc/live-initramfs
 
        mkdir -p $(DESTDIR)/usr/share/doc/live-initramfs/examples
-       cp -r conf/live.conf $(DESTDIR)/usr/share/doc/live-initramfs/examples
+       cp -r conf/* $(DESTDIR)/usr/share/doc/live-initramfs/examples
 
        # Installing manpages
        set -e; for MANPAGE in manpages/*.en.1; \
index a6550e5..b81a6af 100755 (executable)
@@ -48,13 +48,16 @@ SAFE_TMPDIR="/live"
 # Permits multiple runs
 MOUNTP="$(mktemp -d -p ${SAFE_TMPDIR} live-snapshot-mnt.XXXXXX)"
 DEST="${MOUNTP}/live-sn.cpio.gz"
+DEF_SNAP_COW="/live/cow"
+TMP_FILELIST="${PROGRAM}.list"
 
 # Command line defaults and declarations
-SNAP_COW="/live/cow"
+SNAP_COW="${DEF_SNAP_COW}"
 SNAP_DEV=""
 SNAP_OUTPUT=""
 SNAP_RESYNC_STRING=""
 SNAP_TYPE="cpio"
+SNAP_LIST="/etc/live-snapshot.list"
 
 Error ()
 {
@@ -312,21 +315,61 @@ Mount_device ()
        esac
 }
 
+Do_filelist ()
+{
+       # BUGS: supports only cpio.gz types right now
+       TMP_FILELIST=$1
+       if [ -f "${SNAP_LIST}" ]
+       then
+               # Generate include list
+               for entry in $(cat "${SNAP_LIST}" | grep -v '^#.*$' | grep -v '^ *$')
+               do
+                       if [ -f "${entry}" ]
+                       then
+                               printf "%s\000" "${entry}" >> "${TMP_FILELIST}"
+                       elif [ -d "${entry}" ]
+                       then
+                               cd /
+                               find "${entry}" -print0 >> "${TMP_FILELIST}"
+                               cd "${OLDPWD}"
+                       fi
+               done
+
+               if [ "${SNAP_COW}" = "${DEF_SNAP_COW}" ]
+               then
+                       # Relative to rootfs
+                       echo "/"
+               else
+                       # Mostly "/home"
+                       echo "${SNAP_COW}"
+               fi
+       else
+               cd "${SNAP_COW}"
+               find . -path '*.wh.*' -prune -o -print0 >> "${TMP_FILELIST}"
+               cd "${OLDPWD}"
+               echo "${SNAP_COW}"
+       fi
+}
+
 Do_snapshot ()
 {
+       TMP_FILELIST=$(mktemp -p "${SAFE_TMPDIR}" "${TMP_FILELIST}.XXXXXX")
+
        case "${SNAP_TYPE}" in
                squashfs)
-                       EXCLUDE_LIST="$(mktemp -p ${SAFE_TMPDIR} live-snapshot-exclude-list.XXXXXX)"
-                       echo "./${EXCLUDE_LIST}" > "${EXCLUDE_LIST}"
+                       echo ".${TMP_FILELIST}" > "${TMP_FILELIST}"
+                       # Removing whiteheads of unionfs
                        cd "${SNAP_COW}"
-                       find . -name '*.wh.*' >> "${EXCLUDE_LIST}"
+                       find . -name '*.wh.*' >> "${TMP_FILELIST}"
                        cd "${OLDPWD}"
-                       mksquashfs "${SNAP_COW}" "${DEST}" -ef "${EXCLUDE_LIST}"
-                       rm -f "${EXCLUDE_LIST}"
+                       mksquashfs "${SNAP_COW}" "${DEST}" -ef "${TMP_FILELIST}"
                        ;;
 
                cpio)
-                       ( cd "${SNAP_COW}" && find . -path '*.wh.*' -prune -o -print0 | cpio --quiet -o0 -H newc | gzip -9c > "${DEST}" ) || exit 1
+                       WORKING_DIR=$(Do_filelist "${TMP_FILELIST}")
+                       cd "${WORKING_DIR}"
+                       cat "${TMP_FILELIST}" | cpio --quiet -o0 -H newc | gzip -9c > "${DEST}" || exit 1
+                       cd "${OLDPWD}"
                        ;;
 
                ext2|ext3)
@@ -339,6 +382,11 @@ Do_snapshot ()
                        mkfs.jffs2 --root="${SNAP_COW}" --output="${DEST}"
                        ;;
        esac
+
+       if [ -f "${TMP_FILELIST}" ]
+       then
+               rm -f "${TMP_FILELIST}"
+       fi
 }
 
 Clean ()
diff --git a/conf/live-snapshot.list b/conf/live-snapshot.list
new file mode 100644 (file)
index 0000000..30fe29d
--- /dev/null
@@ -0,0 +1,18 @@
+# /etc/live-snapshot resync list example
+#
+# If this file is present, each uncommented not empty line will be parsed when
+# running live-snapshot and included in target snapshot.
+#
+# The syntax for the line is just a full file or directory pathname.
+# Those files and directories, and only those will be included on automatic persistence handling.
+
+# Include itself for reuse
+/etc/live-snapshot.list
+
+# Include networking setups
+/etc/network/interfaces
+/etc/resolv.conf
+/etc/hosts
+
+# Include the whole Desktop directory of the default user
+/home/user/Desktop
index fdca25b..f57413d 100644 (file)
@@ -77,6 +77,14 @@ show usage and exit
 
 output version information and exit
 
+Files
+-----
+
+  /etc/live-snapshot.list
+
+This optional file, if present changes the behaviour of live-snapshot, only files and directories listed there are included (integrally) in the snapshot.
+Beware, it is an experimental feature that only works for cpio targets now.
+
 See also
 --------
 
index 3892bed..fd1ac04 100644 (file)
@@ -83,6 +83,15 @@ mostra l'utilizzo ed esce
 
 da informazioni sulla versione ed esce
 
+Files
+-----
+
+  /etc/live-snapshot.list
+
+Facoltativo, se presente cambia completamente il funzionamento di live-snapshot; solo i files e le directory elencate verranno effettivamente inclusi nello snapshot.
+Attenzione, e` una funzionalita` sperimentale che funziona attualmente solo con gli snapshot di tipo "cpio".
+
+
 See also
 --------
 
index ee363c3..e211263 100755 (executable)
@@ -875,7 +875,7 @@ try_snap ()
                        fi
                else
                        # cpio.gz snapshot
-                       if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null)
+                       if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories > /dev/null 2>&1)
                        then
                                log_warning_msg "Impossible to include the ${snapfile} Snapshot"
                                return 1