Backing up and Importing IMAP folders

Konstantin Khomoutov flatworm at users.sourceforge.net
Thu Oct 20 17:36:35 UTC 2016


On Thu, 20 Oct 2016 16:57:45 +0300 (EEST)
Aki Tuomi <aki.tuomi at dovecot.fi> wrote:

[...]
> > Alternatively you can use `dsync` to perform backup with a native
> > Dovecot tool.  It's able to sync mailboxes of any Dovecot user --
> > including synchronizing a mailbox to an empty (yet) spool.
> > You'll need to do a bit of shell scripting which would spin around
> > calling `doveadm user *` and feeding its output to something like
> > 
> >   while read user; do \
> >     dest="/var/backup/dovecot/$user";
> >     mkdir -p "$dest" && chown vmail:vmail "$dest" \
> >       && chmod 0755 "$dest"
> >     dsync -u "$user" backup "maildir:$dest" \
> >   done
> > 
> > Note that you will only need this if you don't want to shut down
> > Dovecot to copy its mail spool out.
> 
> You can also use doveadm backup -A maildir:%u/

Could you please elaborate?

I have a typical "virtual users" setup where I do have

  mail_home = /var/local/mail/%Ln
  mail_location = maildir:~/mail

and everything is stored with uid=vmail / gid=vmail (much like
described in the wiki, that is).

I'd like to use a single call to `doveadm backup -A ...` to back up the
whole /var/local/mail/* to another location (say, /var/backups/dovecot/)
so that is has the same structure, just synchronized with the spool.
(The purpose is to then backup the replica off-site).

I tried to call

  doveadm backup -A maildir:/var/backups/dovecot/%u

and it created a directory "/var/backups/dovecot/%u" (with literal
"%u", that is), created what appeared to be a single mailbox structure
under it and after a while scared a heck out of me with a series of
error messages reading

dsync(user1): Error: Mailbox INBOX sync: mailbox_delete failed: INBOX
can't be deleted.
dsync(user2): Error: Mailbox INBOX sync: mailbox_delete failed: INBOX
can't be deleted.
...

for each existing user.

It appears that it luckily failed to delete anything in the source
directory (though I have no idea what it actually tried to do).

Reading the doveadm-backup(1) multiple times still failed to shed a
light for me on how to actually backup the whole maildir hierarchy for
all existing users.

So, the question: how do I really should go about backing up the whole
mailbox hierarchy in the case of virtual users?


More information about the dovecot mailing list