Smart ZimaOS Cleanup Script (Safe for System with Backups)
This is a safe and modular cleanup script that helps free up space on ZimaOS without touching critical system files or breaking running containers.
It’s especially useful when / shows 100% full (which is normal on ZimaOS) but your /DATA drive is filling up due to backups, Docker layers, or cached files from heavy apps.
What this script does
Keeps only your newest backups (auto-removes older ones)
Clears logs and temporary cache folders
Safely prunes Docker images and volumes
Works on any ZimaOS setup
Easy to extend for your own apps
Full Script:
cat > /DATA/clean_zima_storage_safe.sh <<'EOF'
#!/bin/bash
echo "=== ZimaOS Smart Cleanup Started ==="
# --- 1. Backup rotation (keeps newest only)
if [ -d "/DATA/Backups" ]; then
echo "Checking backups in /DATA/Backups..."
for backup_dir in "/DATA/Backups"/*; do
if [ -d "$backup_dir" ]; then
echo "Processing $backup_dir..."
cd "$backup_dir"
folders=($(ls -1t 2>/dev/null))
keep="${folders[0]}"
for f in "${folders[@]:1}"; do
echo "Removing old backup: $f"
rm -rf "$f"
done
cd /
fi
done
else
echo "No backup directory found, skipping..."
fi
# --- 2. Clear system logs
if [ -d "/DATA/.log" ]; then
echo "Clearing logs..."
rm -rf /DATA/.log/*
fi
# --- 3. App-specific cache cleanup (modular section)
# Add or remove apps here as needed
declare -A APPS_TO_CLEAN=(
[immich]="/tmp /cache"
[nextcloud]="/tmp /cache /data/updater-*/backups"
[plex-nvidia]="/Library/Application Support/Plex Media Server/Cache"
[jellyfin]="/cache /metadata/Temp"
[netdata]="/cache"
)
for app in "${!APPS_TO_CLEAN[@]}"; do
app_dir="/DATA/AppData/$app"
if [ -d "$app_dir" ]; then
echo "Cleaning cache for $app..."
for path in ${APPS_TO_CLEAN[$app]}; do
target="$app_dir$path"
if [ -d "$target" ]; then
echo " - Removing $target"
rm -rf "$target"/*
fi
done
fi
done
# --- 4. Docker cleanup (safe mode)
echo "Running Docker cleanup..."
docker system prune -f
docker volume prune -f
echo "=== Cleanup complete. Run 'df -h /DATA' to check free space ==="
EOF
chmod +x /DATA/clean_zima_storage_safe.sh
Run manually
To execute the main cleanup script you created above, run the following command.
This command launches the script from /DATA, triggering all cleanup tasks immediately — including backup rotation, log clearing, app cache cleanup, and Docker pruning.
You can run it any time you want to safely free up space on your system.
chmod +x /DATA/clean_zima_storage_safe.sh
bash /DATA/clean_zima_storage_safe.sh
Add your own apps
To include another app, just add a new line under APPS_TO_CLEAN, for example:
[paperless-ngx]="/data/tmp /data/cache"
The script will automatically detect and clean those folders safely.
Example result
After running this on my system:
/DATAusage dropped from 82% to 46%- Freed up over 500 GB
- System remained stable
- The newest “my apps” backup was preserved
Safety notes
- Only affects
/DATA(never system files under/) - Keeps newest backups automatically
- Skips missing folders
- Works for ZimaOS 1.4-1.5+, including CasaOS