Skip to content

Instantly share code, notes, and snippets.

@cPFence
Created March 2, 2025 11:50
Show Gist options
  • Save cPFence/12ea501396cb9df74100b61a9ba497b7 to your computer and use it in GitHub Desktop.
Save cPFence/12ea501396cb9df74100b61a9ba497b7 to your computer and use it in GitHub Desktop.
Delete Old Snapshot Backups in Enhance v12 ext4
# Dry-run version
DAYS=2
SECONDS_OLD=$((DAYS * 86400))
for site in /backups/*; do
[ -d "$site" ] || continue
current_snapshot=$(readlink "$site/current")
echo "Checking site: ${site##*/}"
find "$site" -maxdepth 1 -type d -name "snapshot-*" | while read -r snapshot; do
if [ "$snapshot" = "$current_snapshot" ]; then
echo " Skipping current snapshot: $snapshot"
continue
fi
timestamp=${snapshot##*-}
timestamp=$((timestamp / 1000))
snapshot_date=$(date -d @$timestamp '+%Y-%m-%d %H:%M:%S')
if (( $(date +%s) - timestamp > SECONDS_OLD )); then
echo " [DRY-RUN] Would delete: $snapshot ($snapshot_date)"
fi
done
done
#################################################
############### Use with Caution ##############
#################################################
# Delete version
DAYS=2
SECONDS_OLD=$((DAYS * 86400))
for site in /backups/*; do
[ -d "$site" ] || continue
current_snapshot=$(readlink "$site/current")
echo "Checking site: ${site##*/}"
find "$site" -maxdepth 1 -type d -name "snapshot-*" | while read -r snapshot; do
if [ "$snapshot" = "$current_snapshot" ]; then
echo " Skipping current snapshot: $snapshot"
continue
fi
timestamp=${snapshot##*-}
timestamp=$((timestamp / 1000))
snapshot_date=$(date -d @$timestamp '+%Y-%m-%d %H:%M:%S')
if (( $(date +%s) - timestamp > SECONDS_OLD )); then
echo " Deleting: $snapshot ($snapshot_date)"
rm -rf "$snapshot"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment