| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 | <head> |
| 5 | <title>Cyrus IMAP Server: Replication Examples</title> |
| 6 | </head> |
| 7 | <body> |
| 8 | <h1>Cyrus IMAP Server: Replication Examples</h1> |
| 9 | |
| 10 | <h2>Introduction</h2> |
| 11 | |
| 12 | <p>The replication system creates a link between two Cyrus mailstores: a |
| 13 | master and a replica system. Both systems can be live mailstores with |
| 14 | active users: here in Cambridge we install systems in pairs.</p> |
| 15 | |
| 16 | <p>Typically half of the users will be using each system, and each system |
| 17 | replicates to its partner. In the event of a failover everyone uses the |
| 18 | remaining system in a pair. This is typically safe as the IMAP/POP/SMTP |
| 19 | servers define which of the two systems is the live server for any given |
| 20 | account, and the replica just plays a game of follow my leader.</p> |
| 21 | |
| 22 | <p>Occasionally I think about introducing some form of sanity check so that we |
| 23 | have to explicitly issue a command to the remaining backend system as well |
| 24 | as the proxies in the event of a failover.</p> |
| 25 | |
| 26 | <h2>A short example of replication in action</h2> |
| 27 | |
| 28 | <pre> |
| 29 | Index: |
| 30 | |
| 31 | #: Annotation |
| 32 | C: Command issued by client |
| 33 | S: Command issued by server |
| 34 | |
| 35 | # Authentication between systems is done using SSH key based authentication: |
| 36 | |
| 37 | C: $ ssh -x cyrus-2 /usr/local/cyrus/bin/sync_server |
| 38 | S: * Sync Server v0.0 [EXPERIMENTAL] |
| 39 | |
| 40 | # Create new auth_state and ask for all information about given list of |
| 41 | # folders (namely user.dpc22). Returns: |
| 42 | # |
| 43 | # "**" unsolicited response for each mailbox. Returns: |
| 44 | # Folder UniqueID, Name, ACL, UIDlast, timestamp for last seen update. |
| 45 | # |
| 46 | # "*" response for each mail message in folder: |
| 47 | # UID, GUID, flags (other than \Seen state) |
| 48 | |
| 49 | C: user_some dpc22 user.dpc22 |
| 50 | S: ** 6b98205c796c6c61 user.dpc22 \ |
| 51 | S: "dpc22 lrswipcda anonymous 0 " 4151 1062945305 |
| 52 | S: * 1 000000000000000000000000 () |
| 53 | S: * 3697 0101003f4c56b00545000000 () |
| 54 | S: * 3919 0101003f4c56b04b2900000d () |
| 55 | S: * 3937 0101003f4c56b0514900001f () |
| 56 | S: * 4066 0101003f4c56b07422000002 () |
| 57 | S: * 4089 0101003f4c56b07e56000023 (\answered) |
| 58 | S: * 4118 0101003f4c56b08328000016 () |
| 59 | S: * 4131 0101003f4c56b084d7000002 () |
| 60 | S: * 4136 0101003f4c56b087f3000001 () |
| 61 | S: * 4140 0101003f4c56b08c9d000026 () |
| 62 | S: OK User_Some finished |
| 63 | |
| 64 | # Select a folder to work with |
| 65 | |
| 66 | C: select user.dpc22 |
| 67 | S: OK 6b98205c796c6c61 4151 1062945305 |
| 68 | |
| 69 | # Remove message with UID "1" from folder list (message which has been |
| 70 | # sitting in my inbox since January, has no GUID defined) |
| 71 | |
| 72 | C: expunge 1 |
| 73 | S: OK Expunge Complete |
| 74 | |
| 75 | # Set some user flags on message UID "4140" |
| 76 | |
| 77 | C: setflags 4140 (hello world) |
| 78 | S: OK Updated flags on 1 messages okay |
| 79 | |
| 80 | # Demonstrate that something has changed: |
| 81 | |
| 82 | C: status |
| 83 | S: * 3697 0101003f4c56b00545000000 () |
| 84 | S: * 3919 0101003f4c56b04b2900000d () |
| 85 | S: * 3937 0101003f4c56b0514900001f () |
| 86 | S: * 4066 0101003f4c56b07422000002 () |
| 87 | S: * 4089 0101003f4c56b07e56000023 (\answered) |
| 88 | S: * 4118 0101003f4c56b08328000016 () |
| 89 | S: * 4131 0101003f4c56b084d7000002 () |
| 90 | S: * 4136 0101003f4c56b087f3000001 () |
| 91 | S: * 4140 0101003f4c56b08c9d000026 (hello world) |
| 92 | S: OK 4151 |
| 93 | |
| 94 | # Now lets correct the damage that we just inflicted: |
| 95 | |
| 96 | C: $ replicate -s cyrus-2 -v -v -m user.dpc22 |
| 97 | S: MAILBOXES user.dpc22 |
| 98 | S: USER_SOME dpc22 user.dpc22 |
| 99 | S: SELECT user.dpc22 |
| 100 | S: SETFLAGS [1 msgs] |
| 101 | S: UPLOAD [1 msgs] |
| 102 | S: SETSEEN dpc22 ... |
| 103 | S: ENDUSER |
| 104 | |
| 105 | C: $ ssh -x cyrus-2 /usr/local/cyrus/bin/sync_server |
| 106 | S: * Sync Server v0.0 [EXPERIMENTAL] |
| 107 | S: user_some dpc22 user.dpc22 |
| 108 | S: ** 6b98205c796c6c61 user.dpc22 \ |
| 109 | S: "dpc22 lrswipcda anonymous 0 " 4156 1062968731 |
| 110 | S: * 1 000000000000000000000000 () |
| 111 | S: * 3697 0101003f4c56b00545000000 () |
| 112 | S: * 3919 0101003f4c56b04b2900000d () |
| 113 | S: * 3937 0101003f4c56b0514900001f () |
| 114 | S: * 4066 0101003f4c56b07422000002 () |
| 115 | S: * 4089 0101003f4c56b07e56000023 (\answered) |
| 116 | S: * 4118 0101003f4c56b08328000016 () |
| 117 | S: * 4131 0101003f4c56b084d7000002 () |
| 118 | S: * 4136 0101003f4c56b087f3000001 () |
| 119 | S: * 4140 0101003f4c56b08c9d000026 () |
| 120 | S: OK User_Some finished |
| 121 | |
| 122 | # Back where we started: the replication engine reinserted message UID 0 |
| 123 | # which was missing, and removed "hello world" from message UID 4140 |
| 124 | </pre> |
| 125 | |
| 126 | <h2>Tracking messages between folders</h2> |
| 127 | |
| 128 | <pre> |
| 129 | # I've just saved a message from my inbox into a folder named "zzz", |
| 130 | # creating the folder the process. |
| 131 | |
| 132 | C: $ replicate -s cyrus-2 -v -v -m user.dpc22 user.dpc22.zzz |
| 133 | |
| 134 | Replication action on two MAILBOX objects: |
| 135 | |
| 136 | S: MAILBOXES user.dpc22 user.dpc22.zzz |
| 137 | |
| 138 | Ask server for contents of the two folders: |
| 139 | |
| 140 | S: USER_SOME dpc22 ... |
| 141 | |
| 142 | Reserve message with given GUID in user.dpc22 so that it can be moved |
| 143 | |
| 144 | S: RESERVE user.dpc22 ... |
| 145 | |
| 146 | Remove message from source folder (reserved copy left behind) |
| 147 | |
| 148 | S: SELECT user.dpc22 |
| 149 | S: EXPUNGE [1 msgs] |
| 150 | S: SETSEEN dpc22 ... |
| 151 | |
| 152 | Create target folder and copy in message that we reserved (doesn't have to |
| 153 | be uploaded again) |
| 154 | |
| 155 | S: CREATE user.dpc22.zzz 7f6f384c3f5ba99a |
| 156 | S: "dpc22 lrswipcda anonymous 0 " 0 1062971802 |
| 157 | S: SELECT user.dpc22.zzz |
| 158 | S: UPLOAD [1 msgs] |
| 159 | S: SETSEEN dpc22 ... |
| 160 | S: ENDUSER |
| 161 | </pre> |
| 162 | |
| 163 | </body> |
| 164 | </html> |