Slight corrections to copying logic; avoid deleting a backup when the process has been run twice in a minute

This commit is contained in:
Timothy Allen 2020-04-22 17:15:13 +02:00
parent b8e6933ec0
commit 7ac52b9ea1

View File

@ -9,8 +9,7 @@
# #
epoch=$( date +%Y%m%d%H%M ); epoch=$( date +%Y%m%d%H%M );
#server=10.25.0.1 server=10.25.0.1
server=treehouse.org.za
backups=~/Downloads/firefox backups=~/Downloads/firefox
copy() { copy() {
@ -30,7 +29,9 @@ if [ -x ~/bin/firefox_tabgroups_export.py ]; then
if [ -f ${previous} ]; then if [ -f ${previous} ]; then
if diff -q ${previous} ${backups}/tabs/firefox_tabs.${epoch} >/dev/null; then if diff -q ${previous} ${backups}/tabs/firefox_tabs.${epoch} >/dev/null; then
# No difference, remove this file # No difference, remove this file
if [ ${previous} != ${backups}/tabs/firefox_tabs.${epoch} ]; then
rm ${backups}/tabs/firefox_tabs.${epoch} rm ${backups}/tabs/firefox_tabs.${epoch}
fi
else else
do_copy=1 do_copy=1
fi fi
@ -38,10 +39,10 @@ if [ -x ~/bin/firefox_tabgroups_export.py ]; then
do_copy=1 do_copy=1
fi fi
# Delete backups older than $time # Delete backups older than a year
find ${backups}/tabs -ctime +365 -delete find ${backups}/tabs -ctime +365 -delete
if [ ${do_copy} ]; then if [ ${do_copy} -gt 0 ]; then
for session in ~/.mozilla/firefox/*/sessionstore*/*; do for session in ~/.mozilla/firefox/*/sessionstore*/*; do
sessionfile=$( basename ${session} ) sessionfile=$( basename ${session} )
cp ${session} ${backups}/tabs/sessionstore/${epoch}_${sessionfile} cp ${session} ${backups}/tabs/sessionstore/${epoch}_${sessionfile}
@ -54,11 +55,13 @@ if [ -x ~/bin/firefox_decrypt.py ]; then
do_copy=0 do_copy=0
mkdir -p ${backups}/passwords mkdir -p ${backups}/passwords
previous=$( ls ${backups}/passwords/firefox_passwords.* | tail -1 ) previous=$( ls ${backups}/passwords/firefox_passwords.* | tail -1 )
echo '' | ~/bin/firefox_decrypt.py > ${backups}/passwords/firefox_passwords.${epoch} echo '' | ~/bin/firefox_decrypt.py > ${backups}/passwords/firefox_passwords.${epoch} 2>/dev/null
if [ -f ${previous} ]; then if [ -f ${previous} ]; then
if diff -q ${previous} ${backups}/passwords/firefox_passwords.${epoch} >/dev/null; then if diff -q ${previous} ${backups}/passwords/firefox_passwords.${epoch} >/dev/null; then
# No difference, remove this file # No difference, remove this file
if [ ${previous} != ${backups}/passwords/firefox_passwords.${epoch} ]; then
rm ${backups}/passwords/firefox_passwords.${epoch} rm ${backups}/passwords/firefox_passwords.${epoch}
fi
else else
do_copy=1 do_copy=1
fi fi
@ -66,10 +69,10 @@ if [ -x ~/bin/firefox_decrypt.py ]; then
do_copy=1 do_copy=1
fi fi
# Delete backups older than $time # Delete backups older than a day
find ${backups}/passwords -ctime +1 -delete find ${backups}/passwords -ctime +1 -delete
if [ ${do_copy} ]; then if [ ${do_copy} -gt 0 ]; then
ln -srf ${backups}/passwords/firefox_passwords.${epoch} ${backups}/passwords/firefox_passwords ln -srf ${backups}/passwords/firefox_passwords.${epoch} ${backups}/passwords/firefox_passwords
copy ${backups}/passwords copy ${backups}/passwords
fi fi