81 lines
2.7 KiB
Bash
Executable File
81 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# This script makes local backups of tabs and passwords from Firefox, and then regularly copies them to a backup server
|
|
#
|
|
# firefox_decrypt.py is available from https://github.com/Unode/firefox_decrypt
|
|
#
|
|
# firefox_tabgroups_export.py is available from https://gist.github.com/ssokolow/35097553e5173935e597
|
|
# The version in this repo modifes the original to export only as text
|
|
#
|
|
|
|
epoch=$( date +%Y%m%d%H%M );
|
|
server=10.25.0.1
|
|
#server=treehouse.org.za
|
|
backups=~/Downloads/firefox
|
|
|
|
copy() {
|
|
content=$1
|
|
if [ -e ${content} ] && ping -qc1 ${server} >/dev/null; then
|
|
rsync -a --delete -e 'ssh -i ~/.ssh/id_rsa-firefox_pass' ${content} ${server}:remember/
|
|
#scp -ri ~/.ssh/id_rsa-firefox_pass ${backups}/firefox_tabs.${epoch} ${server}:remember/tabs
|
|
fi
|
|
}
|
|
|
|
if [ -x ~/bin/firefox_tabgroups_export.py ]; then
|
|
do_copy=0
|
|
mkdir -p ${backups}/tabs
|
|
mkdir -p ${backups}/tabs/sessionstore
|
|
previous=$( ls ${backups}/tabs/firefox_tabs.* 2>/dev/null | tail -1 )
|
|
~/bin/firefox_tabgroups_export.py > ${backups}/tabs/firefox_tabs.${epoch}
|
|
if [ -f "${previous}" ]; then
|
|
if diff -q ${previous} ${backups}/tabs/firefox_tabs.${epoch} >/dev/null; then
|
|
# No difference, remove this file
|
|
if [ ${previous} != ${backups}/tabs/firefox_tabs.${epoch} ]; then
|
|
rm ${backups}/tabs/firefox_tabs.${epoch}
|
|
fi
|
|
else
|
|
do_copy=1
|
|
fi
|
|
else
|
|
do_copy=1
|
|
fi
|
|
|
|
# Delete backups older than a year
|
|
find ${backups}/tabs -ctime +365 -delete
|
|
|
|
if [ ${do_copy} -gt 0 ]; then
|
|
for session in ~/.mozilla/firefox/*/sessionstore*/*; do
|
|
sessionfile=$( basename ${session} )
|
|
cp ${session} ${backups}/tabs/sessionstore/${epoch}_${sessionfile}
|
|
done
|
|
copy ${backups}/tabs
|
|
fi
|
|
fi
|
|
|
|
if [ -x ~/bin/firefox_decrypt.py ]; then
|
|
do_copy=0
|
|
mkdir -p ${backups}/passwords
|
|
previous=$( ls ${backups}/passwords/firefox_passwords.* 2>/dev/null | tail -1 )
|
|
echo '' | ~/bin/firefox_decrypt.py > ${backups}/passwords/firefox_passwords.${epoch} 2>/dev/null
|
|
if [ -f "${previous}" ]; then
|
|
if diff -q ${previous} ${backups}/passwords/firefox_passwords.${epoch} >/dev/null; then
|
|
# No difference, remove this file
|
|
if [ ${previous} != ${backups}/passwords/firefox_passwords.${epoch} ]; then
|
|
rm ${backups}/passwords/firefox_passwords.${epoch}
|
|
fi
|
|
else
|
|
do_copy=1
|
|
fi
|
|
else
|
|
do_copy=1
|
|
fi
|
|
|
|
# Delete backups older than a day
|
|
find ${backups}/passwords -ctime +1 -delete
|
|
|
|
if [ ${do_copy} -gt 0 ]; then
|
|
ln -srf ${backups}/passwords/firefox_passwords.${epoch} ${backups}/passwords/firefox_passwords
|
|
copy ${backups}/passwords
|
|
fi
|
|
fi
|