Continuing on from yesterday’s email adventure: Thunderbird Has Lost my eMail in Ubuntu! a prudent preventive measure (I suggested later in the day) is to make sure you always have a current backup of email! There are a few of ways this can be simply handled:
1) Manually copying (duplicating) the “/.mozilla-thunderbird<The Account Profile Name” directory to another location. Not the most realistic solution, or at least not for me because I’ll never do it on a regular schedule.
2) Using software solutions. For example “Bacula” comes to mind: “…Bacula is a set of computer programs that permit you (or the system administrator) to manage backup, recovery, and verification of computer data across a network of computers of different kinds…”
3) Use a simple cron job to automate the backups. One of the forum contributors (Geoff) at http://forums.suselinuxsupport.de/index.php?s=&showtopic=59642&view=findpost&p=243567 provides a nifty, helpful script here:
#!/bin/sh
## Script to backup Thunderbird email
## Backup needs a date (stamp)
set -x
x=`date +%y%m%d.%H%M`
## Save space by making sure backup is archived
tar zcf thunderb-mail-${x}.tgz ~roger/.thunderbird
## Save the compressed backup to mybackup folder
cp thunderb-mail-${x}.tgz /joe/backups/
## Clean up after, we don't need two copies of the backup
rm ~/thunderb-mail-${x}.tgz
Edit the code in his original post, or the code above to your needs. (In other words, where you see “joe” change that word to your account name). For those not overly familiar with cron job configuration, you can find a synopsis here: CronHowto
To run the cron job in our solution we can do the following:
In your Ubuntu distribution, surf to the /usr/bin/ directory and create a folder called “cron_scripts” (or whatever other name is meaningful to you). Place your new script (let’s call it “tb_email_backup”) in cron_scripts. The full path to the script should be:
/usr/bin/cron_scripts/tb_email_backup
To set up the actual cron (tab) job, enter the following command in a terminal:
crontab -e
vi or nano will open for editing.
The syntax to tell cron when to run that backup script (tb_email_backup) and how often looks like this:
* * * * * command to be executed
The first (from left to right) “*” specifies: Minute
The second “*” specifies: Hour
The third “*” specifies: Day
The fourth “*” specifies: Month
The fifth “*” specifies: Week
In this example, we want the backup to be made at 09:30 hrs every day. The command would be:
30 9 * * * /usr/bin/cron_scripts/tb_email_backup
Note: If you don’t want cron job messages, just place “>>/dev/null 2>&1″ to the end of your command.
For more cron help, there’s another good resource here: http://www.linuxhelp.net/guides/cron/
Hopefully this will help yesterday’s “issue”, I’m still waiting for him to tell me how it worked out.


There are 5 comment(s) added so far...
I’ve been using cron to back up Thunderbird and Firefox for almost two years. I keep two backups just in case I backup corrupt data once, twice and I’m SOL.
The monthly cron script:
# backup Thunderbird Local Folders from /UserHome (not same as ~/)
# this process keeps two copies of the monthly Local Folders backup
# first delete the older directory
rm -R /Data/Linux/Internet/Mail_Monthly.previous
# then rename the last backup made
mv /Data/Linux/Internet/Mail_Monthly /Data/Linux/Internet/Mail_Monthly.previous
# then create a new backup
cp -r /UserHome/Thunderbird/xxxxxx.default/Mail /Data/Linux/Internet/Mail_Monthly
I use a montly, weekly and daily backup for Firefox bookmarks. I can afford the GB so I don’t bother with compression. Note the above is just email. Address book is a similar script.
Actually, that’s a good idea. If email is important or valuable, one backup might not be the best way. Extending your idea, a copy could even be FTP’d to another location. Maybe I should add this to the script…
[…] Thunderbird Has Lost my eMail in Ubuntu! Easily Use Cron to Backup Thunderbird eMail in Ubuntu Linux […]
Excellent - that would have to be one of the most clearly written set of instructions I have seen in quite a while. Thank you so much for a very clean solution to this one.
Mind you I still think that Thunderbird should have PROPER Export facilities as part of the application just like any other good email client should.
..Phil
Really cool idea.
I will implement ASAP,
and yes I will also sync with my http://FTP.
cheers,
http://www.felipeferreira.net