---
title: "Server: Ongoing Tasks: External Replication"
description: "Replicate RavenDB databases to external clusters for disaster recovery and geo-distribution with filtered or full replication modes."
url: "https://docs.ravendb.net/7.2/server/ongoing-tasks/external-replication"
version: "7.2"
---

# Server: Ongoing Tasks: External Replication

> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

## Server: Ongoing Tasks: External Replication

> **Note**
>
> - Schedule an **External Replication Task** to have a *live* replica of your data in another database:
>   - In a separate RavenDB cluster [on local machines](https://docs.ravendb.net/7.2/start/getting-started.md) or [a cloud instance](https://docs.ravendb.net/cloud/cloud-overview.md),  
>     which can be used as a failover if the source cluster is down.
>   - In the same cluster if you want a live copy that won't be a client failover target.
>
> - "Live" means that the replica is up to date at all times.  
>   Any changes in the source database will be reflected in the replica once they occur.
>
> - This ongoing task replicates **one-way**, from the source to the destination.  
>   For additional functionality such as filtration and two-way replication consider [Hub/Sink Replication](https://docs.ravendb.net/7.2/server/ongoing-tasks/hub-sink-replication.md).
>
> - To replicate between two separate, secure RavenDB servers,  
>   you need to [pass a client certificate](#step-by-step-guide) from the source server to the destination.
>
> - The External Replication task **does *not* create a backup** of your data and indexes.  
>   See more in [Backup -vs- Replication](https://docs.ravendb.net/7.2/backup/faq.md#is-an-external-replication-task-a-good-substitute-for-a-backup-task)
>
> - In this page:
>   - [General Information about External Replication Task](#general-information-about-external-replication-task)
>   - [Code Sample](#code-sample)
>   - [Step-by-Step Guide](#step-by-step-guide)
>   - [Definition](#definition)
>   - [Offline Behavior](#offline-behavior)
>   - [Delayed Replication](#delayed-replication)

## General Information about External Replication Task

**What is being replicated:**

- All database documents and related data:
  - [Attachments](https://docs.ravendb.net/7.2/document-extensions/attachments/overview.md)
  - [Revisions](https://docs.ravendb.net/7.2/document-extensions/revisions/overview.md)
  - [Counters](https://docs.ravendb.net/7.2/document-extensions/counters/overview.md)
  - [Time Series](https://docs.ravendb.net/7.2/document-extensions/timeseries/overview.md)

**What is *not* being replicated:**

- Server and cluster level features:
  - [Indexes](https://docs.ravendb.net/7.2/indexes/creating-and-deploying.md)
  - [Conflict resolution scripts](https://docs.ravendb.net/7.2/server/clustering/replication/replication-conflicts.md#conflict-resolution-script)
  - [Compare-Exchange](https://docs.ravendb.net/7.2/compare-exchange/overview.md)
  - [Subscriptions](https://docs.ravendb.net/7.2/data-subscriptions/overview.md)
  - [Identities](https://docs.ravendb.net/7.2/server/kb/document-identifier-generation.md#identity-id)
  - Ongoing tasks
    - [ETL](https://docs.ravendb.net/7.2/server/ongoing-tasks/etl/basics.md)
    - [Backup](https://docs.ravendb.net/7.2/backup/create/periodic-tasks/database-backup.md)
    - [Hub/Sink Replication](https://docs.ravendb.net/7.2/studio/database/tasks/ongoing-tasks/hub-sink-replication/overview.md)

      > **Note**
      >
      > **Why are cluster-level features not replicated?**
      >
      > RavenDB is designed with a cluster-level data ownership model to prevent conflicts between clusters,  
      > especially in scenarios where ACID transactions are critical.
      >
      > This approach ensures that certain features, such as policies, configurations, and ongoing tasks,  
      > remain specific to each cluster, avoiding potential inconsistencies.
      >
      > To explore this concept further, refer to the [Data Ownership in a Distributed System](https://ayende.com/blog/196769-B/data-ownership-in-a-distributed-system) blog post.

**Conflicts:**

- Two databases that have an External Replication task defined between them will detect and resolve document
  [conflicts](https://docs.ravendb.net/7.2/server/clustering/replication/replication-conflicts.md) according to each database's conflict resolution policy.
- It is recommended to have the same [policy configuration](https://docs.ravendb.net/7.2/server/clustering/replication/replication-conflicts.md#configuring-conflict-resolution-using-the-client)
  on both the source and the target databases.
  **Sharding Support:**

External replication is supported by both [sharded](https://docs.ravendb.net/7.2/sharding/overview.md) and non-sharded databases.  
Learn more about the way ETL works on a sharded database [here](https://docs.ravendb.net/7.2/sharding/external-replication.md).

## Code Sample

The required elements of an External Replication task are:

- The `UpdateExternalReplicationOperation()` method.
- The destination server needs the [certificate from the source server](https://docs.ravendb.net/7.2/server/security/authentication/certificate-management.md#enabling-communication-between-servers:-importing-and-exporting-certificates)
  so that it will trust the source.
- The [connection string](https://docs.ravendb.net/7.2/server/ongoing-tasks/etl/raven.md#add-a-ravendb-connection-string)
  with the destination server URL and any other details needed to access the destination server.
- The following properties in the `ExternalReplication` object:
  - **ConnectionStringName**  
    The connection string name.
  - **Name**  
    The External Replication task name.

```csharp
Properties
      public class ExternalReplication
      {
          public TimeSpan DelayReplicationFor { get; set; }
          public string Name { get; set; }
          public string ConnectionStringName { get; set; }
          public string MentorNode { get; set; }
      }
```

Optional elements include the following properties in the `ExternalReplication` object:

- **MentorNode**  
  The preferred responsible node in the source server.
- **DelayReplicationFor**  
  The amount of time to delay replication.  
  The following sample shows a 30-minute delay.  Delay can also be set by days, hours, and seconds.

```csharp
//define external replication with mentor node and delay timespan
await sourceStore.Maintenance.SendAsync(
  new UpdateExternalReplicationOperation(new ExternalReplication
{
  ConnectionStringName = connectionStrName,
  Name = "task-name",
  MentorNode = "B",
  DelayReplicationFor = TimeSpan.FromMinutes(30)
}));
         
```

`ExternalReplication` properties:

```csharp
public class ExternalReplication
{
  public TimeSpan DelayReplicationFor { get; set; }
  public string Name { get; set; }
  public string ConnectionStringName { get; set; }
  public string MentorNode { get; set; }
}
```

## Step-by-Step Guide

To create an external replication task via the RavenDB Studio, see the [Step-by-Step Guide](https://docs.ravendb.net/7.2/studio/database/tasks/ongoing-tasks/external-replication-task.md#step-by-step-guide)

## Definition

To learn how to define an external replication task via code, see [code sample](#code-sample).

You can also configure external eplication tasks [via RavenDB Studio](https://docs.ravendb.net/7.2/studio/database/tasks/ongoing-tasks/external-replication-task.md#definition).

## Offline Behavior

- **When the source cluster is down** (and there is no leader):

  - Creating a *new* Ongoing Task is a Cluster-Wide operation,  
    thus, a new Ongoing External Replication Task ***cannot*** be scheduled.

  - If an External Replication Task was *already* defined and active when the cluster went down,  
    then the task will *not* be active and no replication will take place.

- **When the node responsible for the external replication task is down**

  - If the responsible node for the External Replication Task is down,  
    then another node from the Database Group will take ownership of the task so that the external replica is up to date.

- **When the destination node is down:**

  - The external replication will wait until the destination is reachable again and proceed from where it left off.

  - If there is a cluster on the other side, and the URL addresses of the destination database group nodes are listed in the connection string,
    then when the destination node is down, the replication task will simply start transferring data to one of the other nodes specified.

## Delayed Replication

In RavenDB we introduced a new kind of replication, *delayed replication*. It replicates data that is
delayed by `X` amount of time.
*Delayed replication* works just like normal replication but instead of sending data immediately,
it waits `X` amount of time.
Having a delayed instance of a database allows you to "go back in time" and undo contamination to your data
due to a faulty patch script or other human errors.  
While you can and should always use backup for those cases, having a live database makes it quick to failover
to prevent business losses while you repair the faulty databases.

- To set delayed replication, see "3. **Set Replication Delay Time**" in the [definition instructions](https://docs.ravendb.net/7.2/studio/database/tasks/ongoing-tasks/external-replication-task.md#definition).
