Quantcast
Channel: Planet Ubuntu
Viewing all articles
Browse latest Browse all 17727

Alan Pope: Backup Email with OfflineIMAP

$
0
0

I previously blogged about my HP ProLiant MicroServer which I’m playing with for doing backups of remote data and other “small/home office” tasks. I’ve decided to backup my GMail-based email using OfflineIMAP, which is awesome.

Offlineimap is in the Ubuntu repository and is pretty easy to setup once you know the format of the configuration file ‘~/.offlineimaprc’. Something like this is required at the top where the ‘accounts’ line can specify multiple accounts separated by commas.

Note: All of the sections below are in one file – ~/.offlineimaprc

[general]
accounts = alan_example,clare_example
ui = Curses.Blinkenlights
maxsyncaccount = 2

The “ui” parameter defines the look of offlineimap when it’s running. “Curses.Blinkenlights” gives a funky (but sometimes unstable) interface which is useful to use initially because it clearly shows offlineimap working. There’s a screenshot of this running below.

Next we need a section for each account using the name we used in the ‘general’ section above:-

[Account alan_example]
localrepository = gmailLocal_example_alan
remoterepository = gmailRemote_example_alan
autorefresh = 15

[Account clare_example]
localrepository = gmailLocal_example_clare
remoterepository = gmailRemote_example_clare
autorefresh = 60

Next a section to define where the local mail is stored:-

[Repository gmailLocal_example_alan]
type = Maildir
localfolders = /srv/offlineimap/example/alan

[Repository gmailLocal_example_clare]
type = Maildir
localfolders = /srv/offlineimap/example/clare

Finally the settings for the remote repository (your mail store) which in my case is GMail.

[Repository gmailRemote_example_alan]
type = IMAP
remotehost = imap.gmail.com
ssl = yes
remoteport = 993
remoteuser = alan@example.com
remotepass = password
maxconnections = 1
realdelete = no

[Repository gmailRemote_example_clare]
type = IMAP
remotehost = imap.gmail.com
ssl = yes
remoteport = 993
remoteuser = clare@example.com
remotepass = password
maxconnections = 1
realdelete = no

Of course your settings will differ for remoteuser and remotepass, but the rest should work fine. I then ssh to my server and run offlineimap inside Byobu (which I love) and that’s basically it.

Sometimes offlineimap crashes – especially if my internet connection goes down. When offlineimap crashes – or indeed when I quit it nicely, I sometimes get this:-

I then have to issue the reset command because the terminal session becomes unusable.

To avoid this, and to enable me to run offlineimap in the background (once I’ve proved it works okay) I simply change the setting for “ui” in the ~/.offlineimap file from:-

ui = Curses.Blinkenlights

to

ui = Noninteractive.Quiet

Which will cause offlineimap to run and then quit when it's finished. There's no need for the 'autorefresh' options above now, and I can schedule offlineimap to run via the following crontab entry so if my net connection drops it will restart sometime after it comes back up. It will also respawn a new offlineimap 30 mins after the hour if one isn't already running.

*/30 * * * * /usr/bin/offlineimap >/dev/null 2>&1

Now that's all setup I have a full backup of my gmail accounts on local storage. The really cunning thing is that I could point an email client at that store and access my mail locally, even if my Internet connection or GMail goes down.

Digg This  Reddit This  Stumble Now!  Buzz This  Vote on DZone  Share on Facebook  Bookmark this on Delicious  Kick It on DotNetKicks.com  Shout it  Share on LinkedIn  Bookmark this on Technorati  Post on Twitter  Google Buzz (aka. Google Reader)  

Viewing all articles
Browse latest Browse all 17727

Trending Articles