SQLite optimization tool
SQLite database optimization tool. Initially created to speed up firefox but can be used on every database.
You can download it here.
#!/bin/sh # # Description: Clean firefox (or anyother) SQLite database file # Auhtor: Alexandre Joseph <http://alexandrejoseph.com/> # Created: October 31, 2009 # Modified: October 31, 2009 # License: GPL - http://www.gnu.org/copyleft/gpl.html # DB_DIR=~/.mozilla/firefox/*.default # Process name to kill KILL_PROCESS="firefox" # Ask before killing process ASK_KILL=1 # Number of time to do the vaccum REPEAT=1 usage() { echo "usage: $(basename $0) [options]" echo -e "\nOptions:" echo -e "\t-h\t Print this help and exit" echo -e "\t-y\t Kill the running processes without asking" echo -e "\t-p PROCESS_NAME\t Name of the process to kill before clean" echo -e "\t-d DB_DIRECTORY\t Directory path containing the databases" echo -e "\t-n REPEAT_NB\t Number of time to repeat the vaccum" exit 0 } clean_db() { for DB in $(ls $DB_DIR/*.sqlite); do echo -n "Cleaning $(basename $DB)... " sqlite3 $DB "VACUUM" &> /dev/null [ $? -eq 0 ] && echo "Done" || echo "Fail" done } ARGS=$(getopt hyp:d:n: $*) set -- $ARGS for OPT in $ARGS; do case "$OPT" in "-h") help ;; "-y") shift ASK_KILL=0 ;; "-p") shift KILL_PROCESS=$1; shift ;; "-n") shift [ ${1//[^[:digit:]]} = $1 ] && REPEAT=$1 ;; "-d") shift [ -d $1 ] && DB_DIR=$1 || { echo "Directory '$1' does not exists"; exit 1; } ;; "--") shift break ;; esac done # Kill the process if [ "x$(ps x | grep $KILL_PROCESS | grep -v grep)" != "x" ]; then if [ $ASK_KILL -eq 1 ]; then read -p "The process '$KILL_PROCESS' is running, do you want to kill it ? [Y/n] " KILL_IT [ "$KILL_IT" = "n" -o "$KILL_IT" = "N" ] && { echo "Aborting clean up"; exit 0; } fi killall $KILL_PROCESS &> /dev/null fi # Clean the database for ITER in $(seq 1 $REPEAT); do clean_db done