#!/usr/bin/env bash # Check if current user is root if [ "$(id -u)" -ne 0 ]; then echo "This script must be run as root." exit 1 fi mkdir -p /mnt/backup cd /mnt/backup current_date=$(date +%F) # Backup echo "Creating backup of @root subvolume..." btrfs subvolume snapshot -r @root @root_backup_$current_date # Remove backups older than 7 days echo "Removing backups older than 7 days..." find /mnt/backup -maxdepth 1 -type d -name '@root_backup_*' -mtime +7 -exec "echo 'Removing {}' && btrfs subvolume delete {}" \; echo "Backup completed successfully."