How can I migrate Dovecot from one server to another?

Solution 1:

Assuming you're talking about IMAP mailboxes, I would go a different way. Setup the second (virtual) server to your liking, test it and make sure everthing is working as expected. Then use a tool like imapsync to sync/copy over your mailboxes. I have already done this sucessfully a couple of times. You might want to stop your MTA (sendmail, postfix, ...) while you're migrating the mailboxes.

Also have a look at migration page at the dovecot wiki.

Solution 2:

You should copy the configuration file /etc/dovecot.conf and the mail files. Depending on your installation, mail files can be in /var/spool/mail, but also in /home directories. Of course you have to copy also the files (or the tables, or piece of files) needed for login and password validation.

Dovecot has many options for mail storage and user validation, so the file you have to copy are different depending on your configuration.