Monday, April 15, 2013

Vacuum cleaning of $HOME to back it up


I've started with a simple script to compress Firefox's sqlite databases before creating a backup of my $HOME directory

alex@xubuntu:~$ cat bin/vacuumFirefox.sh
#!/bin/bash

[ -n "$(pidof firefox)" ] && {
  echo "ERROR: firefox is still running, close it first!"
  exit 1
}

counterBefore=0
counterAfter=0

for i in ~/.mozilla/firefox/*/*.sqlite; do
  fileSizeBefore=$(du -b $i|awk '{ print $1 }')
  counterBefore=$((counterBefore + fileSizeBefore))
  sqlite3 "$i" vacuum
  fileSizeAfter=$(du -b $i|awk '{ print $1 }')
  counterAfter=$((counterAfter + fileSizeAfter))
  echo "$fileSizeBefore $fileSizeAfter - $(basename $i)"
done
echo "Bytes saved: $(( counterBefore - counterAfter ))"

Here is a sample output: