Files

19 lines
565 B
Bash
Raw Permalink Normal View History

2026-03-12 19:41:34 +07:00
#!/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."