From 8ea9f547ea279c51edde37396fcf894a76fe1d3c Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Mon, 26 Jun 2023 17:04:28 +0200 Subject: [PATCH] add backup script --- README.md | 1 + install-stage1.sh | 12 +++++++-- opt/backup-fs | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 opt/backup-fs diff --git a/README.md b/README.md index dd9ef78..42409b6 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ The scripts will take it from there, asking you for information and downloading - `install-stage1.sh`: sets up the base system and prepares for installation stage 2 - `install-stage2.sh`: continues setting up things after booting into the freshly installed base system - `opt/grub-config`: the custom grub config generator to be installed in /opt/void-usb +- `opt/backup-fs`: helper script to regenerate the squashfs - `procedure.txt`: notes to self, will disappear once finished - `bootup.sh`: script that sets up the overlay - `bashrc`: just a custom bashrc diff --git a/install-stage1.sh b/install-stage1.sh index e022984..2ac52f4 100644 --- a/install-stage1.sh +++ b/install-stage1.sh @@ -185,6 +185,14 @@ echo "%wheel ALL=(ALL:ALL) ALL" > /mnt/target/etc/sudoers.d/wheel_as_sudo_group. # TODO: add overlayfs scripts (bootup and shutdown) +mkdir -p /mnt/target/opt/void-usb +chmod 755 /mnt/target/opt/void-usb +wget --output-document=/mnt/target/opt/void-usb/backup-fs https://lostcave.ddnss.de/git/BodgeMaster/void-minecraft-usb/raw/branch/master/opt/backup-fs +chmod 744 /mnt/target/opt/void-usb/backup-fs + +echo " +/opt/void-usb/backup-fs" >> /mnt/target/etc/rc.shutdown + echo "# See fstab(5). # @@ -280,8 +288,6 @@ run_in_target grub-install --target=i386-pc --boot-directory=/boot/efi/LOADER -- run_in_target grub-install --target=i386-efi --boot-directory=/boot/efi/LOADER --efi-directory=/boot/efi --removable --no-nvram --modules="'$TARGET_PRELOAD_GRUB_MODULES'" "'/dev/$TARGET_DISK'" run_in_target grub-install --target=x86_64-efi --boot-directory=/boot/efi/LOADER --efi-directory=/boot/efi --removable --no-nvram --modules="'$TARGET_PRELOAD_GRUB_MODULES'" "'/dev/$TARGET_DISK'" -mkdir -p /mnt/target/opt/void-usb -chmod 755 /mnt/target/opt/void-usb wget --output-document=/mnt/target/opt/void-usb/grub-config https://lostcave.ddnss.de/git/BodgeMaster/void-minecraft-usb/raw/branch/master/opt/grub-config chmod 744 /mnt/target/opt/void-usb/grub-config @@ -297,4 +303,6 @@ chmod 744 /mnt/target/etc/kernel.d/post-remove/99-void-usb run_in_target xbps-reconfigure -fa +run_in_target /opt/void-usb/backup-fs + # diff --git a/opt/backup-fs b/opt/backup-fs new file mode 100644 index 0000000..7e5face --- /dev/null +++ b/opt/backup-fs @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +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