From a1815079ad4ff8076eb33bbd3f6b50e5c1a66763 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 19 Jan 2017 19:19:24 +0800 Subject: Add various scripts --- unix/backup_thunderbird.sh | 102 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 unix/backup_thunderbird.sh (limited to 'unix/backup_thunderbird.sh') diff --git a/unix/backup_thunderbird.sh b/unix/backup_thunderbird.sh new file mode 100755 index 0000000..1ce311a --- /dev/null +++ b/unix/backup_thunderbird.sh @@ -0,0 +1,102 @@ +#!/bin/sh +# +# Backup thunderbird data with rsync. +# +# Weitian LI +# 2015/01/09 +# + +SCRIPT_PATH=`readlink -f $0` +# Backup destination: same directory as this script. +DEST=`dirname ${SCRIPT_PATH}` + +# rsync options +RSYNC_OPTS="-az" + +VERBOSE=FALSE + +usage() { + echo "Usage:" + echo "`basename $0` [ -hDv ] [ -d ] " + echo "" + echo " -h: show this help" + echo " -D: allow delete destination files" + echo " -v: show verbose information" + echo "" + echo "This script backups thunderbird mails and data with rsync." + echo "" +} + +# disable 'verbose error handling' by preceeding with a colon(:) +while getopts ":hDvd:" opt; do + case $opt in + h) + usage + exit 0 + ;; + D) + RSYNC_OPTS="${RSYNC_OPTS} --delete" + ;; + v) + RSYNC_OPTS="${RSYNC_OPTS} -v" + VERBOSE=TRUE + ;; + d) + DEST="${OPTARG}" + ;; + \?) + echo "Invalid option: -${OPTARG}" >&2 + exit 2 + ;; + :) + echo "Option -${OPTARG} requires an argument." >&2 + exit 3 + ;; + esac +done + +# shift the options processed by getopts +shift $((${OPTIND} - 1)) + +if [ $# -ne 1 ]; then + usage + exit 1 +fi + +# the remaining argument after shift +SRC="$1" + +if [ "${VERBOSE}" = "TRUE" ]; then + echo "RSYNC_OPTS: ${RSYNC_OPTS}" + echo "SRC: ${SRC}" + echo "DEST: ${DEST}" +fi + +# backup files and directories +BACKUP_LIST="ImapMail/" # IMAP mail boxes +BACKUP_LIST="${BACKUP_LIST} Mail/" # POP & Local mail boxes +BACKUP_LIST="${BACKUP_LIST} abook.mab history.mab" # personal & collected addresses +BACKUP_LIST="${BACKUP_LIST} persdict.dat" # personal spelling dictionary +BACKUP_LIST="${BACKUP_LIST} prefs.js" # preferences & tags definitions +BACKUP_LIST="${BACKUP_LIST} key3.db signons.sqlite cert8.db" # saved passwords +#BACKUP_LIST="${BACKUP_LIST} cookies.sqlite permissions.sqlite storage.sdb" # Lightning add-on + +# check files and directories; and rsync +for i in ${BACKUP_LIST}; do + if [ -e "${SRC}/${i}" ]; then + CMD="rsync ${RSYNC_OPTS} '${SRC}/${i}' '${DEST}/${i}'" + if [ "${VERBOSE}" = "TRUE" ]; then + echo "CMD: ${CMD}" + fi + eval ${CMD} + else + echo "${SRC}/${i}: not exist!" >&2 + fi +done + +# log +DATETIME=`date -u +%FT%TZ` +echo "" +echo "Thunderbird data sync finished at ${DATETIME}" +echo "${DATETIME}" >> "${DEST}/SYNC.log" + -- cgit v1.2.2