backup-fs: Deal with overlay showing up as multiple file systems
Before, we would simply pass -one-file-system to mksquashfs, now we go through all mount points to generate a list of all directories to exclude and add the mount points as pseudo files to the squashfs.master
parent
61646d9d04
commit
7ca06298bb
|
@ -27,14 +27,40 @@ function yesno {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
#TODO: remove
|
# cutting off the leading slash allows us to just ignore empty lines below
|
||||||
bash -i < $TTY_OR_CONSOLE
|
readarray -t MOUNT_LIST <<< "$(findmnt --output TARGET --noheadings --raw | sed -e 's|^/||' | sort)"
|
||||||
|
# always ignore /tmp and the package cache
|
||||||
|
EXCLUDE_LIST=("tmp" "var/cache/xbps")
|
||||||
|
|
||||||
|
for I in ${!MOUNT_LIST[@]}; do
|
||||||
|
if [ ! -z "${MOUNT_LIST[$I]}" ]; then
|
||||||
|
FOUND=0
|
||||||
|
for J in ${!EXCLUDE_LIST[@]}; do
|
||||||
|
if grep "${EXCLUDE_LIST[$J]}" > /dev/null <<< "${MOUNT_LIST[$I]}"; then
|
||||||
|
FOUND=1
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# if no parent dir of ${MOUNT_LIST[$I]} is found in $EXCLUDE_LIST
|
||||||
|
if [ $FOUND -eq 0 ]; then
|
||||||
|
EXCLUDE_LIST+=("${MOUNT_LIST[$I]}")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
touch /run/void-usb/backup-fs-excludes
|
||||||
|
touch /run/void-usb/backup-fs-pseudo
|
||||||
|
for I in ${!EXCLUDE_LIST[@]}; do
|
||||||
|
echo "/${EXCLUDE_LIST[$I]}" >> /run/void-usb/backup-fs-excludes
|
||||||
|
FILE_PERMS="$(stat -c '%a %u %g' "${EXCLUDE_LIST[$I]}")"
|
||||||
|
echo "\"/${EXCLUDE_LIST[$I]}\" d $FILE_PERMS" >> /run/void-usb/backup-fs-pseudo
|
||||||
|
done
|
||||||
|
|
||||||
#TODO: refuse to run if system is running
|
#TODO: refuse to run if system is running
|
||||||
|
|
||||||
#TODO: add a way to tell the system whether to back up before shutting down
|
#TODO: add a way to force backing up without asking (for example a file in /run/void-usb)
|
||||||
|
|
||||||
#TODO: colors
|
#TODO: colors (bright white / light gray for readability)
|
||||||
echo "Back up system changes to disk?
|
echo "Back up system changes to disk?
|
||||||
|
|
||||||
This only affects things outside the /home directory.
|
This only affects things outside the /home directory.
|
||||||
|
@ -43,9 +69,7 @@ Backing up the system will take some time.
|
||||||
|
|
||||||
if yesno; then
|
if yesno; then
|
||||||
echo "Backing up..."
|
echo "Backing up..."
|
||||||
#TODO: fiddle with squashfs parameters to find optimal settings
|
mksquashfs / /run/void-usb/container/new_squashfs.img -b 1M -comp xz -progress -noappend -pf /run/void-usb/backup-fs-pseudo -ef /run/void-usb/backup-fs-excludes
|
||||||
#TODO: exclude /tmp
|
|
||||||
mksquashfs / /run/void-usb/container/new_squashfs.img -b 1M -comp xz -one-file-system -progress -noappend -e /var/cache/xbps
|
|
||||||
#TODO: check if enough disk space
|
#TODO: check if enough disk space
|
||||||
# yes -> create new image next to old image
|
# yes -> create new image next to old image
|
||||||
# no -> create new image in RAM
|
# no -> create new image in RAM
|
||||||
|
|
Loading…
Reference in New Issue