Move system backups to snapper

This commit is contained in:
2026-01-09 23:20:35 +01:00
parent 12e9698024
commit bb5855fec9

View File

@@ -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