blob: 1ce311aa27373d2d9d3b72e674767f8f3ca8baba (
plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#!/bin/sh
#
# Backup thunderbird data with rsync.
#
# Weitian LI <liweitianux@gmail.com>
# 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 <dest_dir> ] <thunderbird_profile_dir>"
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"
|