void-minecraft-usb/opt/backup-fs

63 lines
1.4 KiB
Bash

#!/usr/bin/env bash -i
function yesno {
unset DISCARD_ME
while [ -z "$DISCARD_ME" ]; do
read -p "[y/n] " -n1 DISCARD_ME
case "$DISCARD_ME" in
y)
return 0
;;
n)
return 1
;;
*)
echo " Please enter y for yes or n for no."
unset DISCARD_ME
;;
esac
done
}
# Overlay should still be mounted, right?
cat /proc/mounts
read -p "
press any key" -n1 DISCARD_ME
# And no services running?
ps aux | grep -vF "[kworker"
read -p "
press any key" -n1 DISCARD_ME
#TODO: remove above debugging sanity checks
#TODO: refuse to run if system is running
#TODO: add a way to tell the system whether to back up before shutting down
#TODO: colors
echo "Back up system changes to disk?
This only affects things outside the /home directory.
Backing up the system will take some time.
"
if yesno; then
echo "Backing up..."
#TODO: fiddle with squashfs parameters to find optimal settings
#TODO: What (if any) device nods need to be created? (man mksquashfs -> pseudo file)
mksquashfs / /container/new_squashfs.img -b 1M -comp xz -one-file-system -progress -noappend -e /var/cache/xbps
#TODO: check if enough disk space
# yes -> create new image next to old image
# no -> create new image in RAM
#TODO: figure out when appending to existing squashfs is a good idea
mv /container/new_squashfs.img /container/squashfs.img
else
echo ""
echo "Not backing up."
fi