Backup mails – setup imapsync
For backup of my mails, I have started with setup a local Dovecot instance (Backup mails – setup of a dovecot server).
Back in the days, I already searched for a solution and used imapsync. Because of my own examples how to use it and good experience with it, I used it again. It will be used to sync the mails between my main mailaccount and the local Dovecot accounts.
Install imapsync
To install imapsync, some software needs to be installed. From the official install documentation, you get the for different os the instructions, what and how to install. For me it is Ubuntu.
sudo apt-get install \ libauthen-ntlm-perl \ libclass-load-perl \ libcrypt-openssl-rsa-perl \ libcrypt-ssleay-perl \ libdata-uniqid-perl \ libdigest-hmac-perl \ libdist-checkconflicts-perl \ libencode-imaputf7-perl \ libfile-copy-recursive-perl \ libfile-tail-perl \ libio-compress-perl \ libio-socket-inet6-perl \ libio-socket-ssl-perl \ libio-tee-perl \ libjson-webtoken-perl \ libmail-imapclient-perl \ libmodule-scandeps-perl \ libnet-dbus-perl \ libnet-ssleay-perl \ libpar-packer-perl \ libproc-processtable-perl \ libreadonly-perl \ libregexp-common-perl \ libsys-meminfo-perl \ libterm-readkey-perl \ libtest-fatal-perl \ libtest-mock-guard-perl \ libtest-mockobject-perl \ libtest-pod-perl \ libtest-requires-perl \ libtest-simple-perl \ libunicode-string-perl \ liburi-perl \ libtest-nowarnings-perl \ libtest-deep-perl \ libtest-warn-perl \ make \ time \ cpanminus
sudo cpanm Mail::IMAPClientgit clone https://github.com/imapsync/imapsync.git
cd imapsync
./imapsync --testslive
Setup imapsync
For each account, I want to sync, I setup a shell script with the commands to start the sync.
#!/usr/bin/bashIf you want to try out first, if login to the two servers with the account data works, uncomment the last line and add a \ at the end of the „Trash“. In that case, imapsync will try to connect and give you some information about, if connections were successful.
./imapsync \
--host1 imap.example.com --port1 993 --user1 username --password1 secretpassword --ssl1 \
--host2 localhost --port2 143 --user2 testaccount --password2 secretpassword2 --nossl2 --delete2 \
--nofoldersizes --exclude Trash
# --dry --justlogin
With the shell script you should be able to sync mails between first and second mail account. First sync can take some time, depending on the amount of mails.
Gmail options
If you have a gmail account, there is an option, which optimize the handling for gmail. If gmail is the first (source) account, add –gmail1. Information about handling and options can be found in the imapsync documentation for gmail. Important is the part to receive an app password for your gmail/google account! This is my shell script to sync gmail into the Dovecot instance.
#!/usr/bin/bash
./imapsync \
--host1 imap.gmail.com --port1 993 --user1 yourmail@gmail.com --password1 apppassword --ssl1 --gmail1 \
--host2 localhost --port2 143 --user2 verena --password2 secretpassword --nossl2 --delete2 \
--nofoldersizes --exclude Trash
# --dry --justlogin
[…] Next step will be setup of imapsync, which will be used to sync the mails by imap protocol. […]
[…] setting up a Dovecot instance and having imapsync running, how could I do the main task, the […]