10 size=$(fs_size "${fromdev}" "" "used")
12 if [ -b "${fromdev}" ]
14 log_success_msg "Copying snapshot ${fromdev} to ${todir}..."
17 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
19 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
20 freespace=$(df -k | awk '/'${todev}'/{print $4}')
22 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
25 tomount="/mnt/tmpsnap"
27 if [ ! -d "${tomount}" ]
32 fstype=$(get_fstype "${fromdev}")
37 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
38 cp -a "${tomount}"/* ${todir}
41 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
46 if echo ${fromdev} | grep -qs loop
48 losetup -d "${fromdev}"
53 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
60 # copy the contents of previously found snapshot to ${snap_mount}
61 # and remember the device and filename for resync on exit in live-boot.init
68 if [ -z "${snap_relpath}" ]
70 # root snapshot, default usage
73 # relative snapshot (actually used just for "/home" snapshots)
74 snap_mount="${2}${snap_relpath}"
77 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
79 log_success_msg "found snapshot: ${snapdata}"
80 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
81 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
82 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
84 if ! try_mount "${snapdev}" "${snapback}" "ro"
91 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
93 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
94 dev=$(get_backing_device "${snapback}/${snapfile}")
96 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
101 # Unfortunately klibc's cpio is incompatible with the
102 # rest of the world; everything else requires -u -d,
103 # while klibc doesn't implement them. Try to detect
104 # whether it's in use.
105 cpiopath="$(which cpio)" || true
106 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
110 cpioargs='--unconditional --make-directories'
113 if [ -s "${snapback}/${snapfile}" ]
116 cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
120 log_warning_msg "${snapback}/${snapfile} is empty, adding it for sync on reboot."
124 if [ "${RES}" != "0" ]
126 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
130 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
132 if [ "${RES}" != "0" ]
134 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
137 elif [ -b "${snapdata}" ]
139 # Try to find if it could be a snapshot partition
141 log_success_msg "found snapshot ${snap_type} device on ${dev}"
142 if echo "${dev}" | grep -qs loop
144 # strange things happens, user confused?
145 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
146 snapfile=$(basename ${snaploop})
147 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
152 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
154 log_warning_msg "Impossible to include the ${snap_type} Snapshot (i)"
157 if [ -n "${snapfile}" ]
159 # it was a loop device, user confused
164 log_warning_msg "Impossible to include the ${snap_type} Snapshot (o)"
168 if [ -z ${PERSISTENCE_READONLY} ]
170 echo "export ${snap_type}SNAP=${snap_relpath}:${snapdev}:${snapfile}" >> snapshot.conf # for resync on reboot/halt