2020-04-22 14:49:49 +00:00
|
|
|
#!/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 );
|
2020-04-22 15:15:13 +00:00
|
|
|
server=10.25.0.1
|
2020-04-26 20:12:13 +00:00
|
|
|
#server=treehouse.org.za
|
2020-04-22 14:49:49 +00:00
|
|
|
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
|
2020-04-24 18:15:57 +00:00
|
|
|
previous=$( ls ${backups}/tabs/firefox_tabs.* 2>/dev/null | tail -1 )
|
2020-04-22 14:49:49 +00:00
|
|
|
~/bin/firefox_tabgroups_export.py > ${backups}/tabs/firefox_tabs.${epoch}
|
2020-04-24 18:15:57 +00:00
|
|
|
if [ -f "${previous}" ]; then
|
2020-04-22 14:49:49 +00:00
|
|
|
if diff -q ${previous} ${backups}/tabs/firefox_tabs.${epoch} >/dev/null; then
|
|
|
|
# No difference, remove this file
|
2020-04-22 15:15:13 +00:00
|
|
|
if [ ${previous} != ${backups}/tabs/firefox_tabs.${epoch} ]; then
|
|
|
|
rm ${backups}/tabs/firefox_tabs.${epoch}
|
|
|
|
fi
|
2020-04-22 14:49:49 +00:00
|
|
|
else
|
|
|
|
do_copy=1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
do_copy=1
|
|
|
|
fi
|
|
|
|
|
2020-04-22 15:15:13 +00:00
|
|
|
# Delete backups older than a year
|
2020-04-22 14:49:49 +00:00
|
|
|
find ${backups}/tabs -ctime +365 -delete
|
|
|
|
|
2020-04-22 15:15:13 +00:00
|
|
|
if [ ${do_copy} -gt 0 ]; then
|
2020-04-22 14:49:49 +00:00
|
|
|
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
|
2020-04-26 20:12:13 +00:00
|
|
|
previous=$( ls ${backups}/passwords/firefox_passwords.* 2>/dev/null | tail -1 )
|
2020-04-22 15:15:13 +00:00
|
|
|
echo '' | ~/bin/firefox_decrypt.py > ${backups}/passwords/firefox_passwords.${epoch} 2>/dev/null
|
2020-04-24 18:15:57 +00:00
|
|
|
if [ -f "${previous}" ]; then
|
2020-04-22 14:49:49 +00:00
|
|
|
if diff -q ${previous} ${backups}/passwords/firefox_passwords.${epoch} >/dev/null; then
|
|
|
|
# No difference, remove this file
|
2020-04-22 15:15:13 +00:00
|
|
|
if [ ${previous} != ${backups}/passwords/firefox_passwords.${epoch} ]; then
|
|
|
|
rm ${backups}/passwords/firefox_passwords.${epoch}
|
|
|
|
fi
|
2020-04-22 14:49:49 +00:00
|
|
|
else
|
|
|
|
do_copy=1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
do_copy=1
|
|
|
|
fi
|
|
|
|
|
2020-04-22 15:15:13 +00:00
|
|
|
# Delete backups older than a day
|
2020-04-22 14:49:49 +00:00
|
|
|
find ${backups}/passwords -ctime +1 -delete
|
|
|
|
|
2020-04-22 15:15:13 +00:00
|
|
|
if [ ${do_copy} -gt 0 ]; then
|
2020-04-22 14:49:49 +00:00
|
|
|
ln -srf ${backups}/passwords/firefox_passwords.${epoch} ${backups}/passwords/firefox_passwords
|
|
|
|
copy ${backups}/passwords
|
|
|
|
fi
|
|
|
|
fi
|