Backup Your Mail, Contacts & Calendar
Mail is the linchpin of our modern internet use. Nearly every online account and service relies on it. And yet, most people don’t have a backup!
Contacts & calendars are also important. I would miss so many important events if I suddenly lost my online calendar. And if I lost my contacts, I would have a really hard time finding many people’s info again, especially acquaintances that I don’t contact as often.
Below I describe how I backup these important data using isync/mbsync and pimsync. Read on to see how!
NOTE: I’m using command line programs for this. And, the instructions below assume that you know how to use the terminal, edit files with a text editor, and build software from source.
To backup your data using the GUI, you can use Thunderbird to download a local copy. But, I’m not aware of any workflow for restoring to a new provider using a Desktop App / GUI tool.
Why Backup?፨
Now, most people use an online service that does backups for them, like Google Mail, Microsoft Outlook, Fastmail, and so on. But, what happens if you suddenly and in-explicitly get banned?
This may seem unrealistic, but there are so many horror stories out there of people getting banned after tripping over some automated moderation system.
And since services are more connected than ever, you many not realize that a rogue moderation system from YouTube, Google Cloud Platform, Azure, GitHub, Adsense, and more may bleed through to your entire online presence suddenly going up in smoke.
This is why I pay for my email, use my own domain, and backup my mail, contacts, and calendar!
The Setup፨
I use isync/mbsync for mail and pimsync for contacts and calendar.
These services both work by defining a pair of remotes and sync’ing between them. A remote here is either a server from your provider or a local folder on your machine. And, you can sync between any combination of them.
This means you can do a variety of useful things with these services. Here, I’ll focus on backups. But, this also supports restoring your data to a new provider. And, you can do bidirectional sync to support offline editing.
Sync’ing Your Mail፨
First, install isync/mbsync with your package manager:
# MacOS
brew install isync
# Linux
sudo apt install isync # Ubuntu/Debian/Mint/etc
sudo dnf install isync # RHEL/Fedora/etc
sudo apk install isync # Alpine Linux
sudo pacman -S isync # Arch Linux
# Windows
# Your on your own. Good Luck! I'd suggest just using Window Subsystems for Linux.
Now that you have the program installed, you can write out the configuration
file. This goes at the path ~/.mbsync
. Here’s mine:
# file: ~/.mbsync
Sync Pull
Create Slave
Remove Slave
Expunge Slave
# Setup my personal account
IMAPAccount personal
Host imap.myemailprovider.com
User demo@example.com
PassCmd "pass Internet/myemailprovider.com:backup-password"
# alternatively, hardcode your password with:
# Pass yourpassword
CertificateFile /etc/ssl/certs/ca-certificates.crt
SSLType IMAPS
IMAPStore personal-remote
Account personal
MaildirStore personal-local
SubFolders Verbatim
Path ~/.local/share/mail/personal/
Inbox ~/.local/share/mail/personal/INBOX
Channel personal
Master :personal-remote:
Slave :personal-local:
Patterns *
Create Both
SyncState *
Next, you have to create the data folder with mkdir -p ~/.local/share/mail/personal
.
And finally, you can sync with mbsync -aV
! The program downloads each folder
into the ~/.local/share/mail/personal
directory. And, each email appears as a
separate file.
In the config, notice that the PassCmd
here loads the backup password from a
password manager. I use pass. But, it would
work with any script/program that outputs your password on STDOUT. Or, you can
hardcode the password with Pass yourpassword
.
Sync’ing Your Contacts & Calendar፨
pimsync is a bit more complicated. You have to install it from source. To do that, you can follow these steps:
# Install Rust Toolchain
# See also: https://rustup.rs/
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Download the code
git clone https://git.sr.ht/~whynothugo/pimsync
cd pimsync
# Build the code
make build
# Copy the binary to your PATH
mkdir -p ~/.local/bin # Create this dir if it doesn't already exist
cp ./target/release/pimsync ~/.local/bin/pimsync
If you don’t have ~/.local/bin
on your $PATH
, you need to add that as well
in your ~/.bashrc
or ~/.zshrc
file as follows: export PATH="$PATH:~/.local/bin"
.
To test your install, you can run pimsync version
, which should output the
version of the program. For example:
$ pimsync version
pimsync 0.4.1-91-g43abd3a
Now that the program is installed, you can configure pimsync by creating a file
~/.config/pimsync/pimsync.conf
.
First, you’ll have to create several folders manually before running pimsync
the
first time. Create them with this:
mkdir -p ~/.config/pimsync
mkdir -p ~/.local/share/pimsync/status
mkdir -p ~/.local/share/contacts/cards
mkdir -p ~/.local/share/calendars/events
Then, create your configuration as follows, replacing the URL’s & credentials with the appropriate setup for your provider’s CalDAV & CardDAV services.
# file: ~/.config/pimsync/pimsync.conf
status_path "~/.local/share/pimsync/status/"
storage contacts_mydavprovider {
type carddav
url https://carddav.mydavprovider.com/
username demo@example.com
password {
cmd pass Internet/mydavprovider.com:backup-password
}
# alternatively, hardcode your password with:
# password yourpassword
}
storage contacts_local {
type vdir/vcard
path ~/.local/share/contacts/cards/
fileext vcf
}
pair contacts {
storage_a contacts_local
storage_b contacts_mydavprovider
collections all
}
storage calendars_mydavprovider {
type caldav
url https://caldav.mydavprovider.com/
username demo@example.com
password {
cmd pass Internet/mydavprovider.com:backup-password
}
}
storage calendars_local {
type vdir/icalendar
path ~/.local/share/calendars/events/
fileext ical
}
pair calendars {
storage_a calendars_local
storage_b calendars_mydavprovider
collections all
}
Now, you can check that everything is working by running pimsync check
. If
that returns successfully, you can then sync with pimsync sync contacts
and
pimsync sync calendars
!
Next Steps፨
Now that you have your mail, contacts, and calendar backed up locally, you can back them up with the rest of your files. And, you can rest safely knowing that you will never lose your email, contacts, and calendars.
But, you can also think about doing some more interesting things. For example, you can edit the data locally, offline and sync the other way. That way you can “send emails” while offline and have them delivered later when you are back online.
To do this, you can use any email client that supports maildir format. This is
how mbsync
stores your files. For example, Thunderbird, mutt/neomutt, and aerc
all support the maildir format.
Or, you could do other interesting things with the data like…
- Finetune a large language model to write emails like you do
- Build a graph of your relationships from who are emailed together
- Use ab-bday to create a calendar with all your contact’s birthdays
Conclusion፨
I hope this guide has helped you set up your own backups for email, contacts, and calendar.
This is all possible thanks to open standards like IMAP, CardDAV, and CalDAV. These standards are an important hedge against vendor lock-in and allow you to truly own your data.
It’s really a miracle that these standards exist. They’re an artifact of an older time, when tech companies collaborated to compete on an even playing field and enable outsiders to compete.
The more people use these standards, the more likely they’ll live on for many years to come. So, backup your data!