From 8f908be592645ecdaa9ae4fbff49a787bbdfadc9 Mon Sep 17 00:00:00 2001 From: teldra Date: Mon, 10 May 2021 09:24:40 +0200 Subject: [PATCH] fixes --- files/bin/void-backup | 142 +++++++++++++++++++++------------------- files/bin/void-snapshot | 2 +- 2 files changed, 74 insertions(+), 70 deletions(-) diff --git a/files/bin/void-backup b/files/bin/void-backup index f7cc9c9..e891d7d 100644 --- a/files/bin/void-backup +++ b/files/bin/void-backup @@ -28,85 +28,89 @@ do fhelp exit ;; - update) - update=y - ;; - passwd) - passwd=y - ;; + update) update=y ;; + passwd) passwd=y ;; + clean) do=clean ;; + run) do=run ;; esac done -if [[ -f "${backupcfg}" ]]; then - source "${backupcfg}" -else - echo "${backupcfg} fehlt." - echo "Diese Datei wird normalerweise durch \`void-createbackupcontainer\`" - echo "angelegt. Bitte Sprich mit deinem Systemadministrator." -fi +test -z "${do}" && do=run -if [ -z "${UUID}" ]; then - echo "Keine Backupplatte angegeben." - exit 1 -fi - -if [ ! -e "/dev/disk/by-uuid/${UUID}" ]; then - echo "Bitte Backupfestplatte anschliessen." - exit 1 -fi - -if [ -e /tmp/backup ]; then - echo "Es läuft schon ein Backupvorgang oder wurde nicht richtig beendet." - echo "Bei letzterem: 'sudo rm -rf /tmp/backup'" - exit 1 -fi -touch /tmp/backup - -if [[ "${passwd}" == "y" ]]; then - cryptsetup luksChangeKey "/dev/disk/by-uuid/${UUID}" - rm -rf /tmp/backup - exit 0 -fi - -function finish { - sync - if [ "${poweroff}" = "y" ]; then - shutdown -h now +if [[ ! -f /etc/btrbk/btrbk.conf ]]; then + if [[ -f "${backupcfg}" ]]; then + source "${backupcfg}" + else + echo "${backupcfg} fehlt." + echo "Diese Datei wird normalerweise durch \`void-createbackupcontainer\`" + echo "angelegt. Bitte Sprich mit deinem Systemadministrator." fi - sleep 4 - umount "${ziel}" - echo " " - echo " " - if [[ "${MOUNTEDBY}" == "script" ]]; then - cryptsetup close "luks-${UUID}" - echo "Festplatte kann nun sicher entfernt werden." - elif [[ "${MOUNTEDBY}" == "gnome" ]]; then - echo "Festplatte bitte mit der grafischen Oberflaeche auswerfen (wie ein USB-Stick)" - echo "" - echo "oder:" - echo "sudo umount /dev/mapper/luks-${UUID}" - echo "sudo cryptsetup close luks-${UUID}" - echo "" + + if [ -z "${UUID}" ]; then + echo "Keine Backupplatte angegeben." + exit 1 fi - rm -rf /tmp/backup - echo "FERTIG" -} -trap finish EXIT + if [ ! -e "/dev/disk/by-uuid/${UUID}" ]; then + echo "Bitte Backupfestplatte anschliessen." + exit 1 + fi -if [ ! $(mountpoint -q -x "/dev/mapper/luks-${UUID}") ]; then - if ! cryptsetup open UUID="${UUID}" "luks-${UUID}"; then - echo "Konnte /dev/disk/by-uuid/${UUID} nicht öffnen." + if [ -e /tmp/backup ]; then + echo "Es läuft schon ein Backupvorgang oder wurde nicht richtig beendet." + echo "Bei letzterem: 'sudo rm -rf /tmp/backup'" + exit 1 + fi + touch /tmp/backup + + if [[ "${passwd}" == "y" ]]; then + cryptsetup luksChangeKey "/dev/disk/by-uuid/${UUID}" + rm -rf /tmp/backup + exit 0 + fi + + function finish { + sync + if [ "${poweroff}" = "y" ]; then + shutdown -h now + fi + sleep 4 + umount "${ziel}" + echo " " + echo " " + if [[ "${MOUNTEDBY}" == "script" ]]; then + cryptsetup close "luks-${UUID}" + echo "Festplatte kann nun sicher entfernt werden." + elif [[ "${MOUNTEDBY}" == "gnome" ]]; then + echo "Festplatte bitte mit der grafischen Oberflaeche auswerfen (wie ein USB-Stick)" + echo "" + echo "oder:" + echo "sudo umount /dev/mapper/luks-${UUID}" + echo "sudo cryptsetup close luks-${UUID}" + echo "" + fi + rm -rf /tmp/backup + echo "FERTIG" + + } + trap finish EXIT + + if [ ! $(mountpoint -q -x "/dev/mapper/luks-${UUID}") ]; then + if ! cryptsetup open UUID="${UUID}" "luks-${UUID}"; then + echo "Konnte /dev/disk/by-uuid/${UUID} nicht öffnen." + exit + fi + MOUNTEDBY="script" + else + MOUNTEDBY="gnome" + fi + + if ! mount "/dev/mapper/luks-${UUID}" "${ziel}"; then + echo "Konnte /dev/mapper/luks-${UUID} in ${ziel} nicht mounten." exit fi - MOUNTEDBY="script" else - MOUNTEDBY="gnome" -fi - -if ! mount "/dev/mapper/luks-${UUID}" "${ziel}"; then - echo "Konnte /dev/mapper/luks-${UUID} in ${ziel} nicht mounten." - exit + cfg="/etc/btrbk/btrbk.conf" fi if mountpoint -q /var/lib/backup/quelle/bootfs; then @@ -117,7 +121,7 @@ fi mkdir -p /var/lib/backup/quelle/rootfs/system/backup "/var/lib/backup/ziel/void/rootfs" "/var/lib/backup/ziel/void/homefs" for t in backup "${boot}"; do if [[ "${t}" ]]; then - if ! btrbk --config="${cfg}" --progress --quiet run "${t}"; then + if ! btrbk --config="${cfg}" --progress --quiet "${do}" "${t}"; then btrbk --config="${cfg}" --progress --quiet clean echo "Wegen Fehler nicht herunterfahren." poweroff=n diff --git a/files/bin/void-snapshot b/files/bin/void-snapshot index e636ef8..b8d801a 100644 --- a/files/bin/void-snapshot +++ b/files/bin/void-snapshot @@ -30,7 +30,6 @@ case $1 in ;; *) infos - echo "Falscher aufruf" exit ;; esac @@ -41,6 +40,7 @@ if [ "$#" -eq "0" ]; then fi cfg="/etc/btrbk/btrbk.conf.void" +test -f "/etc/btrbk/btrbk.conf" && cfg="/etc/btrbk/btrbk.conf" if mountpoint -q /var/lib/backup/quelle/bootfs; then mkdir -p "/var/lib/backup/quelle/bootfs/system/snapshots/${word}"