Created
May 28, 2016 21:06
-
-
Save anthonygelibert/2f8a1875ccb2894e71aff7e70646d67a to your computer and use it in GitHub Desktop.
Clean SQLite databases (using VACUUM command)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
for i in **/*.(db|db3|apdb|alfdb|sqlite|sqlite3|dsidx|gcdata|xcindexdb)(.D); do | |
if [[ -z "$(file $i | grep SQLite)" ]]; then | |
continue | |
fi; | |
local -i initialSize="$(du "$i" | cut -f1)" | |
sqlite3 "$i" "VACUUM;" 2> /dev/null | |
[ $? -ne 0 ] && echo "\\033[31mProblem with: $i\\033[0m" && continue | |
local -i newSize="$(du $i | cut -f1)" | |
local -i gain="$((initialSize-newSize))" | |
[ $gain -gt 0 ] && echo "\\033[32m$i: -$((initialSize-newSize)) KB" && continue | |
[ $gain -eq 0 ] && echo "\\033[30m$i: $((initialSize-newSize)) KB" && continue | |
[ $gain -lt 0 ] && echo "\\033[31m$i: +$((newSize-initialSize)) KB" && continue | |
echo -ne "\\033[0m" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment