From bb5855fec97f0670dfae0660f5c047da6a167143 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Fri, 9 Jan 2026 23:20:35 +0100 Subject: [PATCH] Move system backups to snapper --- arch_update | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/arch_update b/arch_update index 05cbc1e..e56d073 100755 --- a/arch_update +++ b/arch_update @@ -1,26 +1,9 @@ -#! /bin/sh - -#Full Arch Linux Update Script +#!/bin/sh +# Full Arch Linux Update Script -SNAPSHOT_DIR=/.snapshots -DAYS_TO_KEEP=30 +set -e -# Backup system -if which btrfs >/dev/null; then - echo -e '\nCreating backup...' >&2 - - cur_time=$(date -Is) - cur_time_s=$(date -d $cur_time +%s) - - for file in $(ls "$SNAPSHOT_DIR"); do - old_time_s=$(date -d $(echo "$file" | sed 's/[[:alpha:]]\+-//') +%s) - if [ $(((cur_time_s - old_time_s) / 86400)) -gt $DAYS_TO_KEEP ]; then - sudo btrfs subvolume delete "$SNAPSHOT_DIR"/"$file" - fi - done - - sudo btrfs subvolume snapshot / "$SNAPSHOT_DIR"/root-$cur_time - sudo btrfs subvolume snapshot /home "$SNAPSHOT_DIR"/home-$cur_time -fi +BACKUP_LIMIT=3 # Check dependencies echo -e '\nInstalling dependencies ...' >&2 @@ -40,6 +23,15 @@ if ! which yay >/dev/null 2>&1; then rm -fr yay fi ! which yaycache >/dev/null 2>&1 && yay -Syu yaycache +# Backup system +if which btrfs >/dev/null; then + yay -Syu --needed snapper + [ ! -f /etc/snapper/configs/root ] && sudo snapper -c root create-config / + [ ! $(sudo awk -F '"' '/NUMBER_LIMIT=/ {print $2}' /etc/snapper/configs/root) -eq $BACKUP_LIMIT ] && sudo sed -i.bak "s/\(NUMBER_LIMIT=\"\).*\"/\1$BACKUP_LIMIT\"/" /etc/snapper/configs/root + + echo -e '\nCreating backup...' >&2 + sudo snapper -c root create -c number +fi # Update mirrors echo -e '\nUpdating mirrors ...' >&2