82 lines
2.6 KiB
Bash
Executable File
82 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Delete Local Snapshot to Free Space
|
|
# Since files are on NAS, it's safe to remove the snapshot
|
|
|
|
set -e
|
|
|
|
echo "=== Delete Local Snapshot to Free Space ==="
|
|
echo ""
|
|
echo "Since your files are safely backed up on NAS, we can delete"
|
|
echo "the local snapshot to free up space."
|
|
echo ""
|
|
|
|
FREE_SPACE_BEFORE=$(df / | tail -1 | awk '{print $4}')
|
|
FREE_SPACE_GB_BEFORE=$(echo "scale=2; $FREE_SPACE_BEFORE / 1024 / 1024" | bc)
|
|
echo "Current free space: ${FREE_SPACE_GB_BEFORE}GB"
|
|
echo ""
|
|
|
|
# Check snapshot
|
|
SNAPSHOT=$(tmutil listlocalsnapshots / 2>/dev/null | grep -v "Snapshots for disk" | grep -v "^$" | head -1)
|
|
if [ -z "$SNAPSHOT" ]; then
|
|
echo "✅ No snapshot found - you're all set!"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Found snapshot: $SNAPSHOT"
|
|
echo ""
|
|
|
|
# Extract date
|
|
SNAP_DATE=$(echo "$SNAPSHOT" | sed 's/.*\.\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}\)\.backup/\1/')
|
|
|
|
if [ -z "$SNAP_DATE" ]; then
|
|
echo "⚠️ Could not parse snapshot date"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Attempting to delete snapshot: $SNAP_DATE"
|
|
echo ""
|
|
|
|
# Try to delete
|
|
if sudo tmutil deletelocalsnapshots "$SNAP_DATE" 2>/dev/null; then
|
|
echo "✅ Successfully deleted snapshot!"
|
|
echo ""
|
|
echo "⏳ Waiting for space to be released..."
|
|
sleep 5
|
|
|
|
FREE_SPACE_AFTER=$(df / | tail -1 | awk '{print $4}')
|
|
FREE_SPACE_GB_AFTER=$(echo "scale=2; $FREE_SPACE_AFTER / 1024 / 1024" | bc)
|
|
FREED_GB=$(echo "scale=2; $FREE_SPACE_GB_AFTER - $FREE_SPACE_GB_BEFORE" | bc)
|
|
|
|
echo ""
|
|
echo "=== Results ==="
|
|
echo " Before: ${FREE_SPACE_GB_BEFORE}GB free"
|
|
echo " After: ${FREE_SPACE_GB_AFTER}GB free"
|
|
if (( $(echo "$FREED_GB > 0" | bc -l) )); then
|
|
echo " ✅ Freed: ${FREED_GB}GB"
|
|
fi
|
|
else
|
|
echo "⚠️ Could not delete snapshot (Stale NFS file handle error)"
|
|
echo ""
|
|
echo "This is a known issue. The snapshot is stuck because:"
|
|
echo " - Time Machine had a stale connection to NAS"
|
|
echo " - The snapshot reference is corrupted"
|
|
echo ""
|
|
echo "=== Solutions ==="
|
|
echo ""
|
|
echo "Option 1: Restart your Mac (Recommended)"
|
|
echo " This will release the stuck snapshot and free the space."
|
|
echo " After restart, the snapshot should be gone."
|
|
echo ""
|
|
echo "Option 2: Wait for macOS to auto-clean"
|
|
echo " macOS will eventually clean up stuck snapshots, but this"
|
|
echo " can take hours or days."
|
|
echo ""
|
|
echo "The good news: The snapshot is a GHOST ENTRY (not in APFS)."
|
|
echo "This means the space may already be available - the entry"
|
|
echo "is just a stale database record that will clear on restart."
|
|
echo ""
|
|
fi
|
|
|
|
echo ""
|