Skip to content

Commit

Permalink
live-snapshot: now supports a static keep file list.
Browse files Browse the repository at this point in the history
* 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.

Signed-off-by: Marco Amadori <marco.amadori@gmail.com>
  • Loading branch information
mammadori authored and daniel-baumann committed Jun 16, 2008
1 parent 824751b commit 03dc8cc
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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; \
Expand Down
62 changes: 55 additions & 7 deletions bin/live-snapshot
Expand Up @@ -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 ()
{
Expand Down Expand Up @@ -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)
Expand All @@ -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 ()
Expand Down
18 changes: 18 additions & 0 deletions conf/live-snapshot.list
@@ -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
8 changes: 8 additions & 0 deletions manpages/live-snapshot.en.1.txt
Expand Up @@ -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
--------

Expand Down
9 changes: 9 additions & 0 deletions manpages/live-snapshot.it.1.txt
Expand Up @@ -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
--------

Expand Down
2 changes: 1 addition & 1 deletion scripts/live
Expand Up @@ -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
Expand Down

0 comments on commit 03dc8cc

Please sign in to comment.