Created
October 31, 2017 07:04
-
-
Save mike1703/47ba2b462a7d68ecff7c5345c7817cfa to your computer and use it in GitHub Desktop.
finds all sqlite databases in the current folder (and subfolders) and executes sqlite3 $FILE "VACUUM;" on all databases
This file contains hidden or 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
#!/bin/bash | |
find -type f \( -name "*.db" -or -name "*.sqlite" \) -print0 | while read -d $'\0' FILE | |
do | |
TYPE=`file "$FILE" | grep -i sqlite` | |
[ -z "$TYPE" ] && continue # this is not an sqlite db | |
PRESIZE=`ls -sh "$FILE" | cut -f 1 -d " "` | |
PRESIZEFULL=`ls -s "$FILE" | cut -f 1 -d " "` | |
sqlite3 "$FILE" "VACUUM;" | |
POSTSIZE=`ls -sh "$FILE" | cut -f 1 -d " "` | |
POSTSIZEFULL=`ls -s "$FILE" | cut -f 1 -d " "` | |
PERCENTAGE=`echo "$POSTSIZEFULL*100/$PRESIZEFULL" | bc` | |
echo -e "$PERCENTAGE%:\t$PRESIZE\t→ $POSTSIZE\t: $FILE" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment