Initial commit: combine nas_tool, nas_webdav, sync-utils

This commit is contained in:
Gan, Jimmy
2026-02-18 22:59:43 +08:00
commit 526c6a5521
77 changed files with 7898 additions and 0 deletions
+161
View File
@@ -0,0 +1,161 @@
#!/bin/bash
# Fix System Data Growth When Deleting Files
# This happens when APFS snapshots preserve deleted files
set -e
echo "=== Fix System Data Growth ==="
echo ""
echo "When you delete files but 'System Data' grows, it means:"
echo " - APFS snapshots are preserving deleted files"
echo " - Time Machine local snapshots are holding space"
echo " - The deleted data is being kept for backup purposes"
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 for snapshots
echo "📸 Checking for snapshots..."
TM_SNAPSHOTS=$(tmutil listlocalsnapshots / 2>/dev/null | grep -v "Snapshots for disk" | grep -v "^$")
SNAP_COUNT=$(echo "$TM_SNAPSHOTS" | grep -v "^$" | wc -l | tr -d ' ')
if [ "$SNAP_COUNT" -gt 0 ]; then
echo " Found $SNAP_COUNT Time Machine snapshot(s):"
echo "$TM_SNAPSHOTS" | sed 's/^/ - /'
else
echo " No Time Machine snapshots found"
fi
APFS_SNAPS=$(diskutil apfs listSnapshots / 2>/dev/null | grep -c "Name:" || echo "0")
echo " Found $APFS_SNAPS APFS snapshot(s)"
echo ""
if [ "$SNAP_COUNT" -eq 0 ] && [ "$APFS_SNAPS" -le 1 ]; then
echo "⚠️ No obvious snapshots, but System Data is still growing."
echo " This may be due to:"
echo " - Time Machine preparing for backup"
echo " - System cache growth"
echo " - Other system processes"
echo ""
fi
echo "🔧 Solution: Disable local snapshots and clean up"
echo ""
read -p "Proceed with cleanup? (y/n) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 0
fi
echo ""
echo "Step 1: Stop Time Machine backup (if running)..."
sudo tmutil stopbackup 2>/dev/null || true
sleep 2
echo " ✓ Stopped"
echo ""
echo "Step 2: Delete all local snapshots..."
if [ "$SNAP_COUNT" -gt 0 ]; then
echo "$TM_SNAPSHOTS" | while read snapshot; do
if [ -n "$snapshot" ]; then
SNAP_DATE=$(echo "$snapshot" | sed 's/.*\.\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}\)\.backup/\1/')
if [ -n "$SNAP_DATE" ]; then
echo " Deleting: $snapshot"
sudo tmutil deletelocalsnapshots "$SNAP_DATE" 2>/dev/null && \
echo " ✅ Deleted" || \
echo " ⚠️ Could not delete (may be in use)"
fi
fi
done
else
echo " No snapshots to delete"
fi
echo ""
echo "Step 3: Aggressively thin all snapshots..."
sudo tmutil thinlocalsnapshots / 1000000000 1 2>&1 || true
echo " ✓ Thinned"
echo ""
echo "Step 4: Disable local snapshots (prevents new ones)..."
# Note: tmutil disablelocal doesn't exist in newer macOS, so we'll use a workaround
# We'll remove Time Machine destination temporarily
echo " ⚠️ To prevent snapshots, you need to:"
echo " 1. Remove Time Machine destination in System Settings"
echo " 2. Or wait for successful backup to clear snapshots"
echo ""
echo "Step 5: Purge system memory and caches..."
if command -v purge &> /dev/null; then
sudo purge
echo " ✓ Purged"
else
echo " ⚠️ Purge command not available"
fi
echo ""
echo "Step 6: Clean user caches..."
rm -rf ~/Library/Caches/* 2>/dev/null || true
echo " ✓ Cleaned"
echo ""
echo "⏳ Waiting for system to update..."
sleep 5
# Check results
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"
else
echo " ⚠️ No space freed yet"
fi
echo ""
echo "=== Critical Next Steps ==="
echo ""
echo "To STOP System Data from growing when you delete files:"
echo ""
echo "1. **Remove Time Machine destination temporarily**:"
echo " System Settings → Time Machine → Remove backup disk"
echo " This prevents new snapshots from being created"
echo ""
echo "2. **Wait 10-15 minutes** after deleting files before checking space"
echo " macOS needs time to release snapshot space"
echo ""
echo "3. **After freeing space, fix Time Machine connection**:"
echo " - Clear credentials in Keychain Access"
echo " - Re-add Time Machine destination"
echo " - Ensure it can successfully connect"
echo ""
echo "4. **Alternative: Use 'Optimize Storage' in System Settings**:"
echo " Apple Menu → About This Mac → Storage → Optimize"
echo " This can help release snapshot space"
echo ""
echo "5. **If System Data keeps growing**:"
echo " - Restart your Mac (releases snapshots)"
echo " - Or remove Time Machine until you have more free space"
echo ""
if (( $(echo "$FREE_SPACE_GB_AFTER < 5" | bc -l) )); then
echo "⚠️ Still critically low on space!"
echo ""
echo " You need to free more space before Time Machine can work."
echo " Consider:"
echo " - Moving large files to NAS"
echo " - Removing unused applications"
echo " - Cleaning Downloads folder"
echo ""
fi
echo ""