Skip to content

Instantly share code, notes, and snippets.

@docwhat
Created March 4, 2012 16:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save docwhat/1973799 to your computer and use it in GitHub Desktop.
Save docwhat/1973799 to your computer and use it in GitHub Desktop.
Script to vacuum all sqlite database on my system
#!/bin/bash
set -eu
echo "Scanning for sqlite databases..."
find \
~/Library\
~/Pictures/\
-type f '(' -iname '*.sqlite' -o -iname '*.db' ')' \
-print0 | while read -r -d $'\0' filename; do
filetype=$(file "${filename}")
if [[ "${filetype}" =~ 'SQLite 3' ]]; then
oldsize=$(stat -c %s "${filename}")
nice sqlite3 "${filename}" vacuum
newsize=$(stat -c %s "${filename}")
if [[ $oldsize -ne $newsize ]]; then
change=$(( 100 - (100 * $newsize) / $oldsize ))
echo "${filename}: ${change}% "
fi
fi
done
# EOF
@xcombelle
Copy link

xcombelle commented Aug 15, 2019

Hi,
I have some discussion on this enhancement from thunderbird and firefox developper who say:
"Thanks. Without the original "pre-vacuum" list it's not possible to give a sensible answer regarding performance. In the future, please document the state before changing your environment."

Have you some "sensible answer" regarding performance, on your case ? I adpated your script to run on my whole home directory with huge succes: thanks a lot https://gist.github.com/xcombelle/ecfa46719cd2ac5f8aeb401b173c7901

The only problem of the script was the display of all file names, which basically hide the information he asked me.
If you have some idea to disable this dispaly you are welcome. (I tried, and have no idea where the dispaly happened.

@docwhat
Copy link
Author

docwhat commented Aug 22, 2019

I don’t use Thunderbird nor do I use this script anymore.

The echo is what prints the file name and percent change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment