3 # live-snapshot - utility to manage Debian Live systems snapshots
5 # This program mount a device (fallback to /tmpfs under /mnt/snapshot
6 # and save the /live/cow (or a different dir) filesystem in it for reusing
7 # in another live-initramfs session. Look at manpage for more info.
9 # Copyright (C) 2006 Marco Amadori <marco.amadori@gmail.com>
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 # On Debian systems, the complete text of the GNU General Public License
26 # can be found in /usr/share/common-licenses/GPL-2 file.
28 PROGRAM="$(basename $0)"
32 if [ -e /etc/live.conf ]
36 USERNAME=$(cat /etc/passwd | grep "999" | cut -f1 -d ':')
41 export USERNAME USERFULLNAME HOSTNAME BUILD_SYSTEM
43 # Source helper functions
44 helpers="/usr/share/initramfs-tools/scripts/live-helpers"
46 if [ -e "${helpers}" ]
50 echo "Error: I cannot found helper functions \"${helpers}\"."
54 # Define LSB log_* functions.
55 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
56 . /lib/lsb/init-functions
67 echo "${PROGRAM} - utility to do Debian Live snapshots"
69 echo "Usage: ${PROGRAM} [-c|--cow DIRECTORY] [-d|--device DEVICE] [-o|--output FILE] [-t|--type TYPE]"
70 echo "Usage: ${PROGRAM} [-r|--resync-string STRING]"
71 echo "Usage: ${PROGRAM} [-h|--help]"
72 echo "Usage: ${PROGRAM} [-u|--usage]"
73 echo "Usage: ${PROGRAM} [-v|--version]"
83 echo "Try \"${PROGRAM} --help\" for more information."
85 if [ ! -z "${MESSAGE}" ]
100 echo " -c, --cow: specifies the copy on write directory (default: /live/cow)."
101 echo " -d, --device: specifies the output snapshot device (default: none)."
102 echo " -o, --output: specifies the output image file (default: ${type} dependent)."
103 echo " -r, --resync-string: internally used to resync previous made snapshots."
104 echo " -t, --type: specifies the snapshot type between \"squashfs\", \"ext2\", \"ext3\" or \"cpio\".gz archive (default: cpio)"
105 echo -e "\nLook at live-snapshot(1) man page for more information."
112 echo "${PROGRAM}, version ${VERSION}"
114 echo "Copyright (C) 2006 Marco Amadori <marco.amadori@gmail.com>"
116 echo "This program is free software; you can redistribute it and/or modify"
117 echo "it under the terms of the GNU General Public License as published by"
118 echo "the Free Software Foundation; either version 2 of the License, or"
119 echo "(at your option) any later version."
121 echo "This program is distributed in the hope that it will be useful,"
122 echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
123 echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
124 echo "GNU General Public License for more details."
126 echo "You should have received a copy of the GNU General Public License"
127 echo "along with this program; if not, write to the Free Software"
128 echo "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA"
130 echo "On Debian systems, the complete text of the GNU General Public License"
131 echo "can be found in /usr/share/common-licenses/GPL-2 file."
133 echo "Homepage: <http://debian-live.alioth.debian.org/>"
142 echo "./tmp/exclude_list" > /tmp/exclude_list
143 ( cd "${COW}" && find . -name '*.wh.*' >> /tmp/exclude_list )
144 mksquashfs "${COW}" "${DEST}" -ef /tmp/exclude_list || exit 1
149 ( cd "${COW}" && find . -path '*.wh.*' -prune -o -print0 | cpio --quiet -o0 -H newc | gzip -9c > "${DEST}" ) || exit 1
153 DU_DIM="$(du -ks ${COW} | cut -f1)"
154 REAL_DIM="$(expr ${DU_DIM} + ${DU_DIM} / 20)" # Just 5% more to be sure, need something more sophistcated here...
155 genext2fs --size-in-blocks=${REAL_DIM} --reserved-blocks=0 --root="${COW}" "${DEST}" || exit 1
159 echo "Internal error."
167 dir1="$(Base_path ${1})"
168 dir2="$(Base_path ${2})"
170 if [ "${dir1}" = "${dir2}" ]
182 ARGUMENTS="$(getopt --longoptions cow:,device:,output,resync-string:,type:,help,usage,version --name=${PROGRAM} --options c:d:o:t:r:,h,u,v --shell sh -- ${ARGS})"
186 echo "Terminating." >&2
190 eval set -- "${ARGUMENTS}"
238 echo "Internal error."; exit 1 ;;
248 if [ ! -d "${MOUNTP}" ]
256 mount -t tmpfs -o rw tmpfs "${MOUNTP}"
258 if [ ! -L /home/${USERNAME}/Desktop/live-snapshot ]
260 ln -s "${MOUNTP}" /home/${USERNAME}/Desktop/live-snapshot
265 try_mount "${dev}" "${MOUNTP}" rw
272 MOUNTP="/mnt/live-snapshot"
275 DEST="${MOUNTP}/live-sn.cpio.gz"
277 DESKTOP_LINK=/home/${USERNAME}/Desktop/live-snapshot
279 if [ -n "${SNAP_RSTRING}" ]
281 COW=$(echo "${SNAP_RSTRING}" | cut -f1 -d ':')
282 DEV=$(echo "${SNAP_RSTRING}" | cut -f2 -d ':')
283 DEST=$(echo "${SNAP_RSTRING}" | cut -f3 -d ':')
299 Usage "Unregognized String"
305 # Bad options handling
306 if [ -z "${SNAP_COW}" ]
313 case "${SNAP_TYPE}" in
314 "cpio"|"squashfs"|"ext2"|"ext3")
323 Usage "Error: unrecognized snapshot type"
334 Usage "Error: ${COW} is not a directory"