5 CephFS supports asynchronous replication of snapshots to a remote CephFS file
6 system via `cephfs-mirror` tool. Snapshots are synchronized by mirroring
7 snapshot data followed by creating a snapshot with the same name (for a given
8 directory on the remote file system) as the snapshot being synchronized.
13 The primary (local) and secondary (remote) Ceph clusters version should be
19 For a given snapshot pair in a directory, `cephfs-mirror` daemon will rely on
20 readdir diff to identify changes in a directory tree. The diffs are applied to
21 directory in the remote file system thereby only synchronizing files that have
22 changed between two snapshots.
24 This feature is tracked here: https://tracker.ceph.com/issues/47034.
26 Currently, snapshot data is synchronized by bulk copying to the remote
29 .. note:: Synchronizing hardlinks is not supported -- hardlinked files get
30 synchronized as separate files.
35 Start by creating a user (on the primary/local cluster) for the mirror daemon.
36 This user requires write capability on the metadata pool to create RADOS
37 objects (index objects) for watch/notify operation and read capability on the
42 ceph auth get-or-create client.mirror mon 'profile cephfs-mirror' mds 'allow r' osd 'allow rw tag cephfs metadata=*, allow r tag cephfs data=*' mgr 'allow r'
44 Create a user for each file system peer (on the secondary/remote cluster). This user needs
45 to have full capabilities on the MDS (to take snapshots) and the OSDs::
47 $ ceph fs authorize <fs_name> client.mirror_remote / rwps
49 This user should be used (as part of peer specification) when adding a peer.
51 Starting Mirror Daemon
52 ----------------------
54 Mirror daemon should be spawned using `systemctl(1)` unit files::
56 $ systemctl enable cephfs-mirror@mirror
57 $ systemctl start cephfs-mirror@mirror
59 `cephfs-mirror` daemon can be run in foreground using::
61 $ cephfs-mirror --id mirror --cluster site-a -f
63 .. note:: User used here is `mirror` as created in the `Creating Users` section.
68 CephFS supports asynchronous replication of snapshots to a remote CephFS file system
69 via `cephfs-mirror` tool. For a given directory, snapshots are synchronized by transferring
70 snapshot data to the remote file system and creating a snapshot with the same name as the
71 snapshot being synchronized.
73 Snapshot Synchronization Order
74 ------------------------------
76 Although the order in which snapshots get chosen for synchronization does not matter,
77 snapshots are picked based on creation order (using snap-id).
82 A snapshot may be deleted and recreated (with the same name) with different contents.
83 An "old" snapshot could have been synchronized (earlier) and the recreation of the
84 snapshot could have been done when mirroring was disabled. Using snapshot names to
85 infer the point-of-continuation would result in the "new" snapshot (incarnation)
86 never getting picked up for synchronization.
88 Snapshots on the secondary file system stores the snap-id of the snapshot it was
89 synchronized from. This metadata is stored in `SnapInfo` structure on the MDS.
94 `Mirroring` module (manager plugin) provides interfaces for managing directory snapshot
95 mirroring. Manager interfaces are (mostly) wrappers around monitor commands for managing
96 file system mirroring and is the recommended control interface.
98 Mirroring Module and Interface
99 ------------------------------
101 Mirroring module provides interface for managing directory snapshot mirroring. The module
102 is implemented as a Ceph Manager plugin. Mirroring module does not manage spawning (and
103 terminating) the mirror daemons. Right now the preferred way would be to start/stop
104 mirror daemons via `systemctl(1)`. Going forward, deploying mirror daemons would be
105 managed by `cephadm` (Tracker: http://tracker.ceph.com/issues/47261).
107 The manager module is responsible for assigning directories to mirror daemons for
108 synchronization. Multiple mirror daemons can be spawned to achieve concurrency in
109 directory snapshot synchronization. When mirror daemons are spawned (or terminated)
110 , the mirroring module discovers the modified set of mirror daemons and rebalances
111 the directory assignment amongst the new set thus providing high-availability.
113 .. note:: Multiple mirror daemons is currently untested. Only a single mirror daemon
116 Mirroring module is disabled by default. To enable mirroring use::
118 $ ceph mgr module enable mirroring
120 Mirroring module provides a family of commands to control mirroring of directory
121 snapshots. To add or remove directories, mirroring needs to be enabled for a given
122 file system. To enable mirroring use::
124 $ ceph fs snapshot mirror enable <fs_name>
126 .. note:: Mirroring module commands use `fs snapshot mirror` prefix as compared to
127 the monitor commands which `fs mirror` prefix. Make sure to use module
130 To disable mirroring, use::
132 $ ceph fs snapshot mirror disable <fs_name>
134 Once mirroring is enabled, add a peer to which directory snapshots are to be mirrored.
135 Peers follow `<client>@<cluster>` specification and get assigned a unique-id (UUID)
136 when added. See `Creating Users` section on how to create Ceph users for mirroring.
140 $ ceph fs snapshot mirror peer_add <fs_name> <remote_cluster_spec> [<remote_fs_name>] [<remote_mon_host>] [<cephx_key>]
142 `<remote_fs_name>` is optional, and default to `<fs_name>` (on the remote cluster).
144 This requires the remote cluster ceph configuration and user keyring to be available in
145 the primary cluster. See `Bootstrap Peers` section to avoid this. `peer_add` additionally
146 supports passing the remote cluster monitor address and the user key. However, bootstrapping
147 a peer is the recommended way to add a peer.
149 .. note:: Only a single peer is supported right now.
151 To remove a peer use::
153 $ ceph fs snapshot mirror peer_remove <fs_name> <peer_uuid>
155 .. note:: See `Mirror Daemon Status` section on how to figure out Peer UUID.
157 To list file system mirror peers use::
159 $ ceph fs snapshot mirror peer_list <fs_name>
161 To configure a directory for mirroring, use::
163 $ ceph fs snapshot mirror add <fs_name> <path>
165 To stop a mirroring directory snapshots use::
167 $ ceph fs snapshot mirror remove <fs_name> <path>
169 Only absolute directory paths are allowed. Also, paths are normalized by the mirroring
170 module, therefore, `/a/b/../b` is equivalent to `/a/b`.
173 $ ceph fs snapshot mirror add cephfs /d0/d1/d2
175 $ ceph fs snapshot mirror add cephfs /d0/d1/../d1/d2
176 Error EEXIST: directory /d0/d1/d2 is already tracked
178 Once a directory is added for mirroring, its subdirectory or ancestor directories are
179 disallowed to be added for mirroring::
181 $ ceph fs snapshot mirror add cephfs /d0/d1
182 Error EINVAL: /d0/d1 is a ancestor of tracked path /d0/d1/d2
183 $ ceph fs snapshot mirror add cephfs /d0/d1/d2/d3
184 Error EINVAL: /d0/d1/d2/d3 is a subtree of tracked path /d0/d1/d2
186 Commands to check directory mapping (to mirror daemons) and directory distribution are
187 detailed in `Mirror Daemon Status` section.
192 Adding a peer (via `peer_add`) requires the peer cluster configuration and user keyring
193 to be available in the primary cluster (manager host and hosts running the mirror daemon).
194 This can be avoided by bootstrapping and importing a peer token. Peer bootstrap involves
195 creating a bootstrap token on the peer cluster via::
197 $ ceph fs snapshot mirror peer_bootstrap create <fs_name> <client_entity> <site-name>
201 $ ceph fs snapshot mirror peer_bootstrap create backup_fs client.mirror_remote site-remote
202 {"token": "eyJmc2lkIjogIjBkZjE3MjE3LWRmY2QtNDAzMC05MDc5LTM2Nzk4NTVkNDJlZiIsICJmaWxlc3lzdGVtIjogImJhY2t1cF9mcyIsICJ1c2VyIjogImNsaWVudC5taXJyb3JfcGVlcl9ib290c3RyYXAiLCAic2l0ZV9uYW1lIjogInNpdGUtcmVtb3RlIiwgImtleSI6ICJBUUFhcDBCZ0xtRmpOeEFBVnNyZXozai9YYUV0T2UrbUJEZlJDZz09IiwgIm1vbl9ob3N0IjogIlt2MjoxOTIuMTY4LjAuNTo0MDkxOCx2MToxOTIuMTY4LjAuNTo0MDkxOV0ifQ=="}
204 `site-name` refers to a user-defined string to identify the remote filesystem. In context
205 of `peer_add` interface, `site-name` is the passed in `cluster` name from `remote_cluster_spec`.
207 Import the bootstrap token in the primary cluster via::
209 $ ceph fs snapshot mirror peer_bootstrap import <fs_name> <token>
213 $ ceph fs snapshot mirror peer_bootstrap import cephfs eyJmc2lkIjogIjBkZjE3MjE3LWRmY2QtNDAzMC05MDc5LTM2Nzk4NTVkNDJlZiIsICJmaWxlc3lzdGVtIjogImJhY2t1cF9mcyIsICJ1c2VyIjogImNsaWVudC5taXJyb3JfcGVlcl9ib290c3RyYXAiLCAic2l0ZV9uYW1lIjogInNpdGUtcmVtb3RlIiwgImtleSI6ICJBUUFhcDBCZ0xtRmpOeEFBVnNyZXozai9YYUV0T2UrbUJEZlJDZz09IiwgIm1vbl9ob3N0IjogIlt2MjoxOTIuMTY4LjAuNTo0MDkxOCx2MToxOTIuMTY4LjAuNTo0MDkxOV0ifQ==
218 Mirror daemons get asynchronously notified about changes in file system mirroring status
221 CephFS mirroring module provides `mirror daemon status` interface to check mirror daemon
224 $ ceph fs snapshot mirror daemon status
228 $ ceph fs snapshot mirror daemon status | jq
236 "directory_count": 1,
239 "uuid": "02117353-8cd1-44db-976b-eb20609aa160",
241 "client_name": "client.mirror_remote",
242 "cluster_name": "ceph",
243 "fs_name": "backup_fs"
256 An entry per mirror daemon instance is displayed along with information such as configured
257 peers and basic stats. For more detailed stats, use the admin socket interface as detailed
260 CephFS mirror daemons provide admin socket commands for querying mirror status. To check
261 available commands for mirror status use::
263 $ ceph --admin-daemon /path/to/mirror/daemon/admin/socket help
267 "fs mirror status cephfs@360": "get filesystem mirror status",
272 Commands with `fs mirror status` prefix provide mirror status for mirror enabled
273 file systems. Note that `cephfs@360` is of format `filesystem-name@filesystem-id`.
274 This format is required since mirror daemons get asynchronously notified regarding
275 file system mirror status (A file system can be deleted and recreated with the same
278 Right now, the command provides minimal information regarding mirror status::
280 $ ceph --admin-daemon /var/run/ceph/cephfs-mirror.asok fs mirror status cephfs@360
282 "rados_inst": "192.168.0.5:0/1476644347",
284 "a2dc7784-e7a1-4723-b103-03ee8d8768f8": {
286 "client_name": "client.mirror_remote",
287 "cluster_name": "site-a",
288 "fs_name": "backup_fs"
297 `Peers` section in the command output above shows the peer information such as unique
298 peer-id (UUID) and specification. The peer-id is required to remove an existing peer
299 as mentioned in the `Mirror Module and Interface` section.
301 Command with `fs mirror peer status` prefix provide peer synchronization status. This
302 command is of format `filesystem-name@filesystem-id peer-uuid`::
304 $ ceph --admin-daemon /var/run/ceph/cephfs-mirror.asok fs mirror peer status cephfs@360 a2dc7784-e7a1-4723-b103-03ee8d8768f8
308 "last_synced_snap": {
311 "sync_duration": 0.079997898999999997,
312 "sync_time_stamp": "274900.558797s"
320 Synchronization stats such as `snaps_synced`, `snaps_deleted` and `snaps_renamed` are reset
321 on daemon restart and/or when a directory is reassigned to another mirror daemon (when
322 multiple mirror daemons are deployed).
324 A directory can be in one of the following states::
326 - `idle`: The directory is currently not being synchronized
327 - `syncing`: The directory is currently being synchronized
328 - `failed`: The directory has hit upper limit of consecutive failures
330 When a directory hits a configured number of consecutive synchronization failures, the
331 mirror daemon marks it as `failed`. Synchronization for these directories are retried.
332 By default, the number of consecutive failures before a directory is marked as failed
333 is controlled by `cephfs_mirror_max_consecutive_failures_per_directory` configuration
334 option (default: 10) and the retry interval for failed directories is controlled via
335 `cephfs_mirror_retry_failed_directories_interval` configuration option (default: 60s).
337 E.g., adding a regular file for synchronization would result in failed status::
339 $ ceph fs snapshot mirror add cephfs /f0
340 $ ceph --admin-daemon /var/run/ceph/cephfs-mirror.asok fs mirror peer status cephfs@360 a2dc7784-e7a1-4723-b103-03ee8d8768f8
344 "last_synced_snap": {
347 "sync_duration": 0.079997898999999997,
348 "sync_time_stamp": "274900.558797s"
362 This allows a user to add a non-existent directory for synchronization. The mirror daemon
363 would mark the directory as failed and retry (less frequently). When the directory comes
364 to existence, the mirror daemons would unmark the failed state upon successful snapshot
367 When mirroring is disabled, the respective `fs mirror status` command for the file system
368 will not show up in command help.
370 Mirroring module provides a couple of commands to display directory mapping and distribution
371 information. To check which mirror daemon a directory has been mapped to use::
373 $ ceph fs snapshot mirror dirmap cephfs /d0/d1/d2
375 "instance_id": "404148",
376 "last_shuffled": 1601284516.10986,
380 .. note:: `instance_id` is the RADOS instance-id associated with a mirror daemon.
382 Other information such as `state` and `last_shuffled` are interesting when running
383 multiple mirror daemons.
385 When no mirror daemons are running the above command shows::
387 $ ceph fs snapshot mirror dirmap cephfs /d0/d1/d2
389 "reason": "no mirror daemons running",
393 Signifying that no mirror daemons are running and mirroring is stalled.
398 When re-adding (reassigning) a peer to a file system in another cluster, ensure that
399 all mirror daemons have stopped synchronization to the peer. This can be checked
400 via `fs mirror status` admin socket command (the `Peer UUID` should not show up
401 in the command output). Also, it is recommended to purge synchronized directories
402 from the peer before re-adding it to another file system (especially those directories
403 which might exist in the new primary file system). This is not required if re-adding
404 a peer to the same primary file system it was earlier synchronized from.
409 `cephfs-mirror` daemon is built by default (follows `WITH_CEPHFS` CMake rule).