diff --git a/files/bin/void-snapshot b/files/bin/void-snapshot index 569322b..8714a24 100644 --- a/files/bin/void-snapshot +++ b/files/bin/void-snapshot @@ -5,147 +5,45 @@ if [ "${UID}" -ne "0" ]; then fi infos() { - echo "Durch automatische Snapshots wird dein System regelmässig" - echo "(zur Zeit alle zwei Stunden), ohne mehr Platz" - echo "zu verbrauchen, gedoppelt." - echo "Dieses hilft zb. gegen unbeabsichtigtes löschen von Dateien." - echo "Du kannst aktivieren, das sie regelmässig gemacht werden." - echo "Es ist optional, Snapshots auch für privaten Daten zu aktivieren." - echo "Achtung, Daten werden dadurch erst sehr verzögert gelöscht!" -} - -config() { - infos - test -f "/etc/void-snapshot.cfg" || touch "/etc/void-snapshot.cfg" - while read -p "Regelmässige Snapshots aktivieren? [Y/n] " answer; do - test -z "${answer}" && answer="y" - case "${answer}" in - y*|Y*|j*|J*) - if ! grep -q "AUTO" "/etc/void-snapshot.cfg"; then - echo "AUTO=true" >> "/etc/void-snapshot.cfg" - fi - break - ;; - n*|N*) - if grep -q "AUTO" "/etc/void-snapshot.cfg"; then - sed -i '/AUTO/d' "/etc/void-snapshot.cfg" - fi - break - ;; - *) echo "Antwort nicht eindeutig." ;; - esac - done - - answer="" - while read -p "Möchtest du das System automatisch Snapshotten? [Y/n] " answer; do - test -z "${answer}" && answer="y" - case "${answer}" in - y*|Y*|j*|J*) - if ! grep -q "SYSTEMFS" "/etc/void-snapshot.cfg"; then - echo "SYSTEMFS=true" >> "/etc/void-snapshot.cfg" - fi - break - ;; - n*|N*) - if grep -q "SYSTEMFS" "/etc/void-snapshot.cfg"; then - sed -i '/SYSTEMFS/d' "/etc/void-snapshot.cfg" - fi - break - ;; - *) - echo "Antwort nicht eindeutig." ;; - esac - done - - - answer="" - while read -p "Möchtest du deine Privaten Daten automatisch Snapshotten? [Y/n] " answer; do - test -z "${answer}" && answer="y" - case "${answer}" in - y*|Y*|j*|J*) - if ! grep -q "HOMEFS" "/etc/void-snapshot.cfg"; then - echo "HOMEFS=true" >> "/etc/void-snapshot.cfg" - fi - break - ;; - n*|N*) - if grep -q "HOMEFS" "/etc/void-snapshot.cfg"; then - sed -i '/HOMEFS/d' "/etc/void-snapshot.cfg" - fi - break - ;; - *) echo "Antwort nicht eindeutig." ;; - esac - done + echo "Snapshots sind Kopien der Dateien die keinen zusätzlichen Platz" + echo "benötigen." + echo "Es wird bei jedem Update vom Betriebsystem ein Snapshot angelegt." + echo "So ist das Betriebssystem auch bei Problemen bootbar." + echo "Optional kann jede Stunde ein Snapshot der persönlichen Daten" + echo "angelegt werden. Dann verliert man bei versehentlichem löschen" + echo "maximal die Arbeit einer Stunde." + echo "Dafuer folgendes im Terminal ausführen:" + echo 'echo REGULAR_SNAPSHOT_HOME=1 | sudo tee /etc/void-snapshot.cfg' } cron="" update="" -for i in $@; do - case $i in - update) - update=1 - word="update" - SYSTEM=1 - ;; - config) - config - exit - ;; - cron) - cron=1 - word="regular" - ;; - *) - arr+=( "$i" ) - ;; - esac -done - -for i in "${arr[@]}"; do - case $i in - home) - HOMEFS=1 - MANUAL=1 - word="manual" - ;; - system) - SYSTEMFS=1 - MANUAL=1 - word="manual" - ;; - *) - echo unknow word $i - exit - ;; - esac -done +case $1 in + update) + update=1 + word="update" + ;; + cron) + cron=1 + word="regular" + ;; + *) + info + echo "Falscher aufruf" + exit + ;; +esac if [ "$#" -eq "0" ]; then - word="manual" + info + echo "Falscher aufruf" + exit fi cfg="/etc/btrbk/btrbk.conf.void" -if [ "${MANUAL}" ]; then - word=manual -elif [ -z "${MANUAL}" ] && [ -z "${update}" ]; then - if [ ! -f "/etc/void-snapshot.cfg" ]; then - if [ "${cron}" ]; then - echo "no config file found" - echo "create one with: snapshot config" - exit 0 - fi - config || exit - fi - . "/etc/void-snapshot.cfg" -fi +test -f /etc/void-snapshot.cfg && . /etc/void-snapshot.cfg -if [ -z "${AUTO}" ] && [ "${cron}" ]; then - exit 0 -fi - -if [ "${SYSTEMFS}" ]; then - SNAP_BOOT=1 +if [ "${update}" ]; then if mountpoint -q /var/lib/backup/quelle/bootfs; then mkdir -p "/var/lib/backup/quelle/bootfs/system/snapshots/${word}" if ! btrbk --config="${cfg}" --quiet run "${word}boot"; then @@ -154,22 +52,22 @@ if [ "${SYSTEMFS}" ]; then exit fi fi + mkdir -p "/var/lib/backup/quelle/rootfs/system/snapshots/${word}" if ! btrbk --config="${cfg}" --quiet run "${word}root"; then btrbk --config="${cfg}" --quiet clean "${word}root" echo "fail: btrbk --config=${cfg} --quiet run ${word}root" exit fi -fi - -if [ "${HOMEFS}" ] && [ -z "${update}" ]; then - mkdir -p "/var/lib/backup/quelle/rootfs/system/snapshots/${word}" - btrbk --config="${cfg}" --quiet run "${word}home" -fi - - -if [ "${SNAP_BOOT}" ]; then - if ! update-grub 2> /dev/null; then - echo update-grub failed + if [ "${update}" ]; then + if ! update-grub 2> /dev/null; then + echo update-grub failed + fi + fi +elif [ "${cron}" ]; then + if [ "${REGULAR_SNAPSHOT_HOME}" ]; then + mkdir -p "/var/lib/backup/quelle/rootfs/system/snapshots/${word}" + btrbk --config="${cfg}" --quiet run "${word}home" fi fi + diff --git a/files/btrbk/btrbk.conf.void b/files/btrbk/btrbk.conf.void index 22424a6..0192dbd 100644 --- a/files/btrbk/btrbk.conf.void +++ b/files/btrbk/btrbk.conf.void @@ -24,50 +24,27 @@ volume /var/lib/backup/quelle/rootfs # Regular snapshots volume /var/lib/backup/quelle/bootfs - group regularboot cronstats regularstats allstats snapshotstats + group regularboot regularstats allstats snapshotstats snapshot_dir system/snapshots/regular snapshot_preserve_min 4h snapshot_preserve no subvolume bootfs volume /var/lib/backup/quelle/rootfs - group regularroot cronstats regularstats allstats snapshotstats + group regularroot regularstats allstats snapshotstats snapshot_dir system/snapshots/regular snapshot_preserve_min 4h snapshot_preserve no subvolume rootfs volume /var/lib/backup/quelle/rootfs - group regularhome cronstats regularstats allstats snapshotstats + group regularhome regularstats allstats snapshotstats snapshot_dir system/snapshots/regular snapshot_preserve_min 4h snapshot_preserve no subvolume homefs -# Manual Snapshots -volume /var/lib/backup/quelle/bootfs - group manualboot manualstats allstats snapshotstats - snapshot_dir system/snapshots/manual - snapshot_preserve_min latest - snapshot_preserve no - subvolume bootfs - -volume /var/lib/backup/quelle/rootfs - group manualroot manualstats allstats snapshotstats - snapshot_dir system/snapshots/manual - snapshot_preserve_min latest - snapshot_preserve no - subvolume rootfs - -volume /var/lib/backup/quelle/rootfs - group manualhome manualstats allstats snapshotstats - snapshot_dir system/snapshots/manual - snapshot_preserve_min latest - snapshot_preserve no - subvolume homefs - - # Backup volume /var/lib/backup/quelle/bootfs group backupboot backupstats allstats @@ -80,7 +57,7 @@ volume /var/lib/backup/quelle/bootfs target send-receive /var/lib/backup/ziel/void/bootfs volume /var/lib/backup/quelle/rootfs - group backuproot backupstats allstats + group backup backupstats allstats snapshot_dir system/backup snapshot_preserve_min latest snapshot_preserve no @@ -90,7 +67,7 @@ volume /var/lib/backup/quelle/rootfs target send-receive /var/lib/backup/ziel/void/rootfs volume /var/lib/backup/quelle/rootfs - group backuphome backupstats allstats + group backup backupstats allstats snapshot_dir system/backup snapshot_preserve_min latest snapshot_preserve no diff --git a/modules/disk/bios/postconfig b/modules/disk/bios/postconfig index b544eab..785e0ee 100644 --- a/modules/disk/bios/postconfig +++ b/modules/disk/bios/postconfig @@ -78,7 +78,7 @@ mkswap "/dev/mapper/voidvg.${diskid}-swap" mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" btrfs subvol create "${dest}/rootfs" btrfs subvol create "${dest}/homefs" -mkdir -p "${dest}/system/snapshots/{update,regular,manual}" "${dest}/system/backup" +mkdir -p "${dest}/system/snapshots/{update,regular}" "${dest}/system/backup" umount "${dest}" mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" -o subvol=rootfs @@ -89,7 +89,7 @@ if [[ "${cfg[fde_key_store]}" == "once" ]]; then mkfs.btrfs -q -f "${target_boot}" mount "${target_boot}" "${dest}/boot" btrfs subvol create "${dest}/boot/bootfs" - mkdir -p "${dest}/boot/system/snapshots/{update,regular,manual}" "${dest}/boot/system/backup" + mkdir -p "${dest}/boot/system/snapshots/{update,regular}" "${dest}/boot/system/backup" umount "${dest}/boot" mount "${target_boot}" "${dest}/boot" -o subvol=bootfs fi diff --git a/modules/disk/uefi/postconfig b/modules/disk/uefi/postconfig index 9c21029..3c7f113 100644 --- a/modules/disk/uefi/postconfig +++ b/modules/disk/uefi/postconfig @@ -74,7 +74,7 @@ mkswap "/dev/mapper/voidvg.${diskid}-swap" mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" btrfs subvol create "${dest}/rootfs" btrfs subvol create "${dest}/homefs" -mkdir -p "${dest}/system/snapshots/{update,regular,manual}" "${dest}/system/backup" +mkdir -p "${dest}/system/snapshots/{update,regular}" "${dest}/system/backup" umount "${dest}" mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" -o subvol=rootfs @@ -85,7 +85,7 @@ if [[ "${cfg[fde_key_store]}" == "once" ]]; then mkfs.btrfs -q -f "${target_boot}" mount "${target_boot}" "${dest}/boot" btrfs subvol create "${dest}/boot/bootfs" - mkdir -p "${dest}/boot/system/snapshots/{update,regular,manual}" "${dest}/boot/system/backup" + mkdir -p "${dest}/boot/system/snapshots/{update,regular}" "${dest}/boot/system/backup" umount "${dest}/boot" mount "${target_boot}" "${dest}/boot" -o subvol=bootfs fi