FAQ.ISP.txt 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #!/bin/cat
  2. $Id: FAQ.ISP.txt,v 1.14 2022/05/22 08:04:05 gilles Exp gilles $
  3. This document is also available online at
  4. https://imapsync.lamiral.info/FAQ.d/
  5. https://imapsync.lamiral.info/FAQ.d/FAQ.ISP.txt
  6. =======================================================================
  7. Imapsync tips for ISP. Specific issues and solutions.
  8. =======================================================================
  9. * IMAPSync - usage scenario with ISP - by Flavio Zarur Lucarelli
  10. (https://www.lucanet.com.br)
  11. I thought I had to write a quick step by step on my attempts to learn
  12. the imapsync features that matter the most, so it works as we expected
  13. in the scenario in which we use it, which is to migrate customers from
  14. their old ISP to our ISP/email hosting. Thanks to the master Gilles
  15. Lamiral for all his help and hard work.
  16. First of all, remember to use --dry to test things first always and
  17. check the log file to see what would actually happen.
  18. This type of copy keeps destination exactly like source (except, it
  19. doesn't copy duplicates), so use it ONLY before changing your MX to
  20. the new server, as it will delete whatever is in destination which
  21. isn't in source.
  22. imapsync --host1 imap.myisp.com --user1 user@domain.com --password1 pwd \
  23. --host2 imap.myisp.com --user2 user@domain.com --password2 pwd \
  24. --subscribeall --delete2 --delete2folders --addheader
  25. Note: add header adds message ID when it doesn't exist.
  26. This syntax can also be used to sync different source accounts to one
  27. same destination account, simply execute it as many times as desired,
  28. switching source user (user1).
  29. If you have a list of accounts to sync, use this:
  30. https://imapsync.lamiral.info/examples/sync_loop_unix.sh
  31. Adjust the parameters according to the original syntax which I
  32. explained above.
  33. The Sync loop Unix script now outputs an error log, which can be
  34. useful.
  35. We also have shell scripts to check for errors, such as:
  36. - Accounts over quota
  37. grep -R "EXIT_OVERQUOTA" *.txt
  38. - Login error
  39. grep -R "Error login" *.txt
  40. - Check just critical errors
  41. egrep 'EXIT_AUTHENTICATION_FAILURE|EXIT_CONNECTION_FAILURE|EXIT_TLS_FAILURE|EXIT_OVERQUOTA' *.txt
  42. - Check all sorts of errors (can be too much info)
  43. grep 'Exiting with return value' *.txt | grep -v 'Exiting with return value 0'
  44. Also, I like to check log file sizes and compare account sizes on
  45. source and destination.
  46. --
  47. Back to it.
  48. After you do a full sync, check that everything is consistant and
  49. let's proceed to the final stage.
  50. Lower the TTL (ex: 5 min) for the host associated with the MX record,
  51. in the domain's DNS server. Let's say customer has a host mail which
  52. his MX points to, with a high TTL (usually 1 hour). Lower it to 5 min
  53. so that, when you change the MX, it propagates faster.
  54. When comes time to switch over to the new host, do a final sync with
  55. above syntax, before changing the MX. Then, change the MX and tell
  56. your users to start using exclusively the new host.
  57. A few hours after the MX change, we will run Imapsync again. We have
  58. to start preserving emails users move or flags in the new host, which
  59. they started using, so we can't do an exact sync anymore.
  60. One simple solution is the same syntax as before, but without
  61. --delete2 and --delete2folders.
  62. So:
  63. imapsync --host1 imap.myisp.com --user1 user@domain.com --password1 pwd \
  64. --host2 imap.myisp.com --user2 user@domain.com --password2 pwd \
  65. --subscribeall --addheader
  66. The only issue with that syntax is, it would simply copy what is in
  67. source that is not in destination. For example, user might have moved
  68. emails to some sub-folder in host2. However, if you do this once, one
  69. hour after MX change, for example, it's comprehensible that
  70. destination is not exactly as the source anymore.
  71. What we've been doing, especially in the case of huge migrations,
  72. since our destination server auto-archives emails in sub-folders and
  73. changes the hierarchy, is syncing just the last day or few days of
  74. email and just of INBOX.
  75. So we do the sync initially explained in this doc, before the MX
  76. change. Then we auto-archive accounts and after auto-archiving, we
  77. change MX and do a final sync using maxage.
  78. Something like this:
  79. imapsync --host1 imap.myisp.com --user1 user@domain.com --password1 pwd \
  80. --host2 imap.myisp.com --user2 user@domain.com --password2 pwd \
  81. --subscribeall --addheader --maxage 1
  82. If your last full sync was 2 days ago, then use --maxage 2
  83. Goal is to get all the new emails (2 last days) from source.
  84. Another alternative for syncing after the MX change, which Lamiral
  85. suggests, involves deleting emails from source from the last day. I
  86. prefer the method explained above. Anyway, here is this other
  87. scenario...
  88. Something like this:
  89. imapsync --host1 imap.gmail.com --user1 user@domain.com --password1 pwd --ssl1 \
  90. --host2 imap.myisp.com --user2 user@domain.com --password2 pwd --ssl2 \
  91. --folder INBOX --noexpungeaftereach --skipemptyfolders --maxage 1 --delete1
  92. This way, any new email that arrived at source is copied to
  93. destination and deleted from source. Without the --delete1 option,
  94. messages moved on host2 by the user are coming back from host1, and
  95. flags changed on host2 are also reset to what they are on host1.
  96. However, as I wrote before, if you run it just once without --delete1,
  97. perhaps not that bad.
  98. *** Other tips for ISPs
  99. 1) Sync entire account into 1 folder of another account
  100. imapsync --host1 xxx --user1 user1@domain.com --password1 secret1 --ssl1 \
  101. --host2 yyy --user2 user2@domain.com --password2 secret2 --ssl2 \
  102. --addheader --subfolder2 "otheraccountfolder" --delete2 --delete2foldersonly /otheraccountfolder/
  103. Above, user must not be using such destination folder in destination
  104. account until you finish syncing.
  105. I've used it without --delete2 and --delete2foldersonly, as it caused
  106. problems for us, of that folder being unsubscribed in destination...
  107. Don't think it should be a problem as this copy is done usually
  108. without using really using the folder in host2 until you instruct him
  109. to.
  110. Another nice scenario, sync just one folder hierarchy of an account to
  111. another folder of another account.
  112. --subfolder1 test --subfolder2 test2 --delete2 --delete2foldersonly /test2/ --addheader
  113. Also, very useful is to be move emails older than one year, from an
  114. account to another one, to offload the source account.
  115. imapsync ... --subfolder2 "account_user1" --addheader --minage 365 --delete1
  116. So everything older than 365 days is deleted from source. You can even
  117. specify same account for source and recipient, if you want to "delete
  118. older than x days" for the account itself, without moving old emails
  119. to another account.
  120. 2) Translate folder names
  121. I also ended up requiring a regex to translate folder names. On the
  122. old server (Gmail), Sent items were in a folder called [Gmail]/E-mails
  123. enviados and on the new server, its simply called SENT. Same with
  124. lixeira (trash) and rascunhos (drafts).
  125. So this was added:
  126. --regextrans2 "s,\[Gmail\].,," \
  127. --regextrans2 "s,E-mails enviados,Sent," \
  128. --regextrans2 "s,Lixeira,Trash," \
  129. --regextrans2 "s,Rascunhos,Drafts,"
  130. Option --automap is also good to do most of the translate job.
  131. 3) Folders to exclude, to speed up syncs, etc.
  132. imapsync ... --exclude "^Backups" --exclude "(?i)spam" --exclude "(?i)junk" --exclude "(?i)trash" --exclude "(?i)lixeira" --exclude "(?i)Deleted Items"
  133. 4) Delete older than 1 year from an account.
  134. Use the account itself as source and destination and use:
  135. imapsync ... --minage 365 --delete1
  136. 5) Check size of folders in an account. Use Imapsync with same account
  137. as source and destination, with this parameter:
  138. imapsync ... --justfoldersizes
  139. 6) If you have problems copying messages that have labels which are
  140. not supported, there are a few ways out.
  141. We use Dovecot and it doesn't support a series of labels, except the
  142. standard ones. By default, imapsync won't copy messages that have
  143. labels not supported by the recipient server. For that reason, I now
  144. always use --filterbuggyflags and tell customers that not all labels
  145. are copied.
  146. There are other alternatives, such as replacing problematic flags with
  147. other names or copying just standard flags, detailing which ones to
  148. copy, however, --filterbuggyflags was the easiest solution, which
  149. worked fine for us.
  150. 7) Definitely worth reading about dupes, here
  151. https://imapsync.lamiral.info/FAQ.d/FAQ.Duplicates.txt, if you have
  152. problems. Always try to check, even if by sampling, if dupes
  153. occur. In a big migration, when you do several passes, try to check a
  154. few accounts.
  155. The one issue we had with many duplicated emals in the destinatio, was
  156. solved with the first solution in the above FAQ, using this syntax,
  157. when copying from source to the destination, hence effectively
  158. removing the dupes.
  159. imapsync ... --useheader "Message-Id" --delete2duplicates
  160. Note that --delete2duplicates is on when --delete2 is used, unless
  161. --syncduplicates is used or --nodelete2duplicates is used.
  162. =======================================================================
  163. =======================================================================