I've started with a simple script to compress Firefox's sqlite databases before creating a backup of my $HOME directory
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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 ))" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | alex@xubuntu:~$ bin /vacuumFirefox .sh 589824 589824 - addons.sqlite 98304 98304 - chromeappsstore.sqlite 7168 7168 - content-prefs.sqlite 524288 4096 - cookies.sqlite 6144 3072 - downloads.sqlite 589824 589824 - extensions.sqlite 196608 163840 - forecastfox.sqlite 128000 8192 - formhistory.sqlite 5120 4096 - permissions.sqlite 10485760 344064 - places.sqlite 2048 2048 - search.sqlite 112640 111616 - signons.sqlite 262144 262144 - stylish.sqlite 34938880 34938880 - urlclassifier3.sqlite 3072 3072 - webappsstore.sqlite 524288 524288 - addons.sqlite 229376 229376 - content-prefs.sqlite 524288 131072 - cookies.sqlite 98304 98304 - downloads.sqlite 458752 458752 - extensions.sqlite 196608 196608 - formhistory.sqlite 65536 65536 - permissions.sqlite 10485760 1179648 - places.sqlite 327680 327680 - signons.sqlite 98304 98304 - webappsstore.sqlite Bytes saved: 20518912 |
Later this script became a part of a bigger script to backup my $HOME:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | alex@xubuntu:~$ cat bin /backupHome .sh #!/bin/bash homeDir=$HOME destDir= /media/nas/Alex/backup archName= "$(whoami).$(hostname)" # files or directories to exclude printExcludes() { awk '{printf("--exclude ' \ '' %s '\'' ",$1)}' ‹‹EOEXCL .encfs .davfs2 .smbcredentials .cache .eagle .dbus .pulse* .thumbnails Downloads EOEXCL } # vacuum firefox's sqlite files vacuumFirefox() { pidof firefox && { echo "ERROR: firefox is still running, close it first!" return 1 } which sqlite3 &> /dev/null || { echo "ERROR: sqlite3 is not installed. Do 'sudo apt-get install sqlite3' first" return 1 } local counterBefore=0 local counterAfter=0 local fileSizeBefore fileSizeAfter local hDir=$homeDir [ -z "$hDir" ] && hDir=~/ for i in "$hDir" /.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 ))" return 0 } # cleaning phase vacuumFirefox || exit 1 cd "$homeDir" xargs -d \\n -I {} bash -c "rm -rf {}" ‹‹EOLIST .thumbnails/* .cache/* . local /share/Trash/ * .adobe /Flash_Player/AssetCache/ * .mozilla /firefox/ * /Cache/ * EOLIST # creating an archive if [ -d "$destDir" ]; then exe=$( echo "tar -czf \"${destDir}/${archName}.$(date +%Y-%m-%d).tgz\" $(printExcludes) -C $homeDir ./" ) echo "$exe" eval "$exe" else echo "ERROR: Directory $destDir doesn't exist. Canno't create an archive" exit 1 fi |
Inside of the printExcludes I'm also excluding files or directories that contain sensitive informations like passwords in open text.
Note: one can also install the BleachBit utility that can perform a similar job
No comments:
Post a Comment