Sanfte IMAP Migration mit imapsync

Übersicht

Das Perl-Skript imapsync (41K) synchronisiert IMAP-Konten zwischen verschiedenen Servern. Das Tool ermöglicht eine sanfte Migration ohne die Gelesen/Ungelesen-Flags zurückzusetzen.
Aktuelle Version.

Das Tool benötigt folgende Perl-Module:

  • Mail::IMAPClient
  • Digest::MD5
  • Term::ReadKey
  • Digest::HMAC_MD5 (optional)

Manpage

imapsync --help

usage: /usr/bin/imapsync [options]

Several options are mandatory. 

--host1       <string> : "from" imap server. Mandatory.
--port1       <int>    : port to connect on host1. Default is 143.
--user1       <string> : user to login on host1. Mandatory.
--authuser1   <string> : user to auth with on host1 (admin user).
--password1   <string> : password for the user1. Dangerous, use --passfile1
--passfile1   <string> : password file for the user1. Contains the password.
--host2       <string> : "destination" imap server. Mandatory.
--port2       <int>    : port to connect on host2. Default is 143.
--user2       <string> : user to login on host2. Mandatory.
--authuser2   <string> : user to auth with on host2 (admin user).
--password2   <string> : password for the user2. Dangerous, use --passfile2
--passfile2   <string> : password file for the user2. Contains the password.
--noauthmd5            : don't use MD5 authentification.
--authmech1   <string> : auth mechanism to use with host1:
                         PLAIN, LOGIN, CRAM-MD5 etc.
--authmech2   <string> : auth mechanism to use with host2. See --authmech1
--ssl1                 : use an SSL connection on host1.
--ssl2                 : use an SSL connection on host2.
--folder      <string> : sync this folder.
--folder      <string> : and this one, etc.
--folderrec   <string> : sync this folder recursively.
--folderrec   <string> : and this one, etc.
--include     <regex>  : sync folders matching this regular expression
--include     <regex>  : or this one, etc.
                         in case both --include --exclude options are
                         use, include is done before.
--exclude     <regex>  : skips folders matching this regular expression
                         Several folders to avoid:
                          --exclude 'fold1|fold2|f3' skips fold1, fold2 and f3.
--exclude     <regex>  : or this one, etc.
--prefix1     <string> : remove prefix to all destination folders 
                         (usually INBOX. for cyrus imap servers)
                         you can use --prefix1 if your source imap server 
                         does not have NAMESPACE capability.
--prefix2     <string> : add prefix to all destination folders 
                         (usually INBOX. for cyrus imap servers)
                         use --prefix2 if your target imap server does not
                         have NAMESPACE capability.
--regextrans2 <regex>  : Apply the whole regex to each destination folders.
--regextrans2 <regex>  : and this one. etc.
                         When you play with the --regextrans2 option, first
                         add also the safe options --dry --justfolders
                         Then, when happy, remove --dry, remove --justfolders
--regexmess   <regex>  : Apply the whole regex to each message before transfer.
                         Example : 's/\000/ /g' # to replace null by space.
--regexmess   <regex>  : and this one.
--regexmess   <regex>  : and this one, etc.
--regexflag   <regex>  : Apply the whole regex to each flags list.
                         Example : 's/"Junk"//g' # to remove "Junk" flag.
--regexflag   <regex>  : and this one, etc.
--sep1        <string> : separator in case namespace is not supported.
--sep2        <string> : idem.
--delete               : delete messages on source imap server after
                         a successful transfer. Useful in case you
                         want to migrate from one server to another one.
                         With imap, delete tags messages as deleted, they
                         are not really deleted. See expunge.
--delete2              : delete messages on the destination imap server that
                         are not on the source server.
--expunge              : expunge messages on source account.
                         expunge really deletes messages marked deleted.
                         expunge is made at the beginning on the 
                         source server only. newly transferred messages
                         are expunged if option --expunge is given.
                         no expunge is done on destination account but
                         it will change in future releases.
--expunge1             : expunge messages on source account.
--expunge2             : expunge messages on target account.
--syncinternaldates    : sets the internal dates on host2 same as host1
--buffersize  <int>    : sets the size of a block of I/O.
--maxsize     <int>    : skip messages larger than <int> bytes
--maxage      <int>    : skip messages older than <int> days.
                         final stats (skipped) don't count older messages
                         see also --minage
--minage      <int>    : skip messages newer than <int> days.
                         final stats (skipped) don't count newer messages
                         You can do (+ are the messages selected):
                         past|----maxage+++++++++++++++>now
                         past|+++++++++++++++minage---->now
                         past|----maxage+++++minage---->now (intersection)
                         past|++++minage-----maxage++++>now (union)
--skipheader  <regex>  : Don't take into account header keyword 
                         matching <string> ex: --skipheader 'X.*'
--useheader   <string> : Use this header to compare messages on both sides.
                         Ex: Message-ID or Subject or Date.
--useheader   <string>   and this one, etc.
--skipsize             : Don't take message size into account.
--dry                  : do nothing, just print what would be done.
--subscribed           : transfers subscribed folders.
--subscribe            : subscribe to the folders transferred on the 
                         "destination" server that are subscribed
                         on the "source" server.
--(no)foldersizes      : Calculate the size of each "From" folder in bytes
                         and message counts. Meant to be used with
                         --justfoldersizes. Turned on by default.
--justfoldersizes      : exit after printed the folder sizes.
--syncacls             : Synchronises acls (Access Control Lists).
--nosyncacls           : Does not synchronise acls. This is the default.
--debug                : debug mode.
--debugimap            : imap debug mode.
--version              : print software version.
--justconnect          : just connect to both servers and print useful
                         information. Need only --host1 and --host2 options.
--justfolders          : just do things about folders (ignore messages).
--fast                 : be faster (just does not sync flags).
--split1     <int>     : split the requests in several parts on source server.
                         <int > is the number of messages handled per request.
                         default is like --split1 1000
--split2     <int>     : same thing on the "destination" server.
--nofastio1            : don't use fastio with the "from" server.
--nofastio2            : don't use fastio with the "destination" server.
--timeout     <int>    : imap connect timeout.
--help                 : print this.

Example: to synchronise imap account "foo" on "imap.truc.org"
                     to imap account "bar" on "imap.trac.org"

/usr/bin/imapsync \
   --host1 imap.truc.org --user1 foo --passfile1 /etc/secret1 \
   --host2 imap.trac.org --user2 bar --passfile2 /etc/secret2


 Mail::IMAPClient version is 2.2.9
 $Id: imapsync,v 1.219 2007/04/04 09:32:20 gilles Exp $ 
      imapsync copyleft is the GNU General Public License.
      See http://www.gnu.org/copyleft/gpl.html

Funktionen

Migration von INBOX.* nach INBOX.old.*

Es ist empfohlen, dies im safe-mode zu testen.

imapsync \
 ...
 --regextrans2 's/INBOX(.*)/INBOX.old$1/' \
 --dry --justfolders

Wenn die Ausgabe dem entspricht, was wir uns vorgestellt haben, dann ohne –dry.
Anschließend ist die neue Ordnerstruktur auf dem Zielsystem zu überprüfen.
Schlußendlich ist der komplette Transfer ohne –justfolders anzustoßen.

UP

Beispiele/Optionen

INBOX. in den Namen des Ziels verschieben

--regextrans2 's/^INBOX\.(.+)/$1/'

ein komplettes Konto in den Unterordner FOO kopieren

--regextrans2 's/^INBOX(.*)/INBOX.FOO$1/'

wenn auf dem Zielsystem keine ACLs unterstützt werden

--nosyncacls

wenn sich MIME separator IDs bei jedem Zugriff der Mail ändern um Duplikate zu vermeiden

--skipheader '^Content-Type'

wenn nur neuere Mails kopiert werden sollen

--maxage 3650

UP

 
wissen/gpl/imapsync.txt · Zuletzt geändert: 05.09.2010 20:31
 
Recent changes RSS feed Donate Valid XHTML 1.0 Valid CSS Recent cached RSS feed cacert-signed web site: inhalt.serviert.de