Skip to content

Instantly share code, notes, and snippets.

@xcombelle
Created August 15, 2019 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xcombelle/ecfa46719cd2ac5f8aeb401b173c7901 to your computer and use it in GitHub Desktop.
Save xcombelle/ecfa46719cd2ac5f8aeb401b173c7901 to your computer and use it in GitHub Desktop.
This vaccum all database in the home directory
#!/bin/bash
set -eu
echo "Scanning for sqlite databases..."
find \
~\
-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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment