---
title: "CDC Sink: Backup/Restore Task"
description: "How CDC Sink tasks are included in database backups and how they behave when a database is restored, via the RavenDB Client API and the Management Studio."
url: "https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/backup-restore-task"
version: "7.2"
language: "csharp"
---

# CDC Sink: Backup/Restore Task

> Client language: C#.
>
> 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."

> **Note**
>
> - CDC Sink task configuration is stored in the database record,  
>   so it is included in database **backups** (logical and snapshot) and recreated when the database is **restored**.
>
> - Unlike an [imported CDC Sink task](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/export-import-task.md#import-cdc-sink-task),
>   which is created disabled, a restored CDC Sink task keeps the enabled/disabled state it had in the backup,
>   unless you set `DisableOngoingTasks = true`, which disables all ongoing tasks on the restored database.
>
> - In this article:
>   - [Back up CDC Sink task](#back-up-cdc-sink-task)
>     - [Backup via Client API](#backup-via-client-api)
>     - [Backup via Studio](#backup-via-studio)
>   - [Restore CDC Sink task](#restore-cdc-sink-task)
>     - [Restore via Client API](#restore-via-client-api)
>     - [Restore via Studio](#restore-via-studio)
>     - [Restore considerations](#restore-considerations)
>   - [Behavior summary](#behavior-summary)

## Back up CDC Sink task {#back-up-cdc-sink-task}

CDC Sink tasks are backed up automatically as part of the database record.  
No CDC Sink-specific backup setting is required; the task configuration is included in both
[logical and snapshot backups](https://docs.ravendb.net/7.2/backup/overview.md#backup-type).

This applies whether you use a per-database backup task or a [server-wide backup task](https://docs.ravendb.net/7.2/backup/create/periodic-tasks/server-wide-backup.md),  
which applies the backup configuration to each included database.

---

### Backup via Client API

Use `UpdatePeriodicBackupOperation` to create or update a periodic backup task.  
Learn more in [Creating and managing periodic backups using the client API](https://docs.ravendb.net/7.2/backup/create/periodic-tasks/database-backup.md#creating-and-managing-periodic-backups-using-the-client-api).

```csharp
var backupConfig = new PeriodicBackupConfiguration
{
    Name = "DailyBackup",
    BackupType = BackupType.Backup,   // or BackupType.Snapshot
    FullBackupFrequency = "0 2 * * *", // every day at 02:00
    LocalSettings = new LocalSettings { FolderPath = @"/backups/db" }
};

await store.Maintenance.SendAsync(new UpdatePeriodicBackupOperation(backupConfig));
```

---

### Backup via Studio

- Create or manage a periodic backup task in Studio - see
  [Creating and managing periodic backups via Studio](https://docs.ravendb.net/7.2/backup/create/periodic-tasks/database-backup.md#creating-and-managing-periodic-backups-via-studio).

- CDC Sink tasks are included automatically as part of the database record.

## Restore CDC Sink task {#restore-cdc-sink-task}

Restoring the database recreates the CDC Sink task from the database record in the backup.  
The restored task keeps the enabled/disabled state it had in the backup.

Set `DisableOngoingTasks = true` if you do **not** want the CDC Sink task (or any other ongoing task)  
to start after the database is restored.

---

### Restore via Client API

Restore the database with `RestoreBackupOperation`.  
Learn more in [Restoring from backup using the client API](https://docs.ravendb.net/7.2/backup/restore.md#restoring-from-backup-using-the-client-api):

```csharp
var restoreConfig = new RestoreBackupConfiguration
{
    DatabaseName = "RestoredDb",
    BackupLocation = @"/backups/db/2026-07-07-02-00",

    // Recommended when restoring to a new environment so ongoing tasks
    // stay disabled until you've reviewed their settings:
    DisableOngoingTasks = true
};

var restoreOp = await store.Maintenance.Server.SendAsync(
    new RestoreBackupOperation(restoreConfig));
await restoreOp.WaitForCompletionAsync();
```

---

### Restore via Studio

- From **Databases** → **New database** → **from Backup**, choose the backup location.  
  Learn more in [Restoring from backup using Studio](https://docs.ravendb.net/7.2/backup/restore.md#restoring-from-backup-using-studio).

- Enable **Disable ongoing tasks after restore** if you do **not** want the CDC Sink task
  to begin consuming changes until you are ready.

---

### Restore considerations

> **Note**
>
> #### Restored enabled tasks can start immediately
>
> - If `DisableOngoingTasks` is left as `false`,
>   a CDC Sink task that was enabled when the backup was created becomes **active immediately**
>   and can connect to the source database.
>
> - When restoring to a new environment, verify the connection string and source availability first.  
>   For **PostgreSQL**, also confirm that the referenced publication exists and that the replication slot
>   can be consumed, or configure dedicated names before enabling the restored task.
>
> - The task's saved CDC progress is restored from the [`@cdc-states/<task name>` document](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/how-it-works.md#the-state-document)
>   as it existed in the backup. If no matching state document exists, the task starts fresh
>   and performs an initial load unless `SkipInitialLoad` is set.

> **Note**
>
> #### PostgreSQL: shared replication slot
>
> - Restore copies the task's `SlotName` and `PublicationName` unchanged.
>
> - A PostgreSQL replication slot can be consumed by **only one connection at a time**.  
>   If the origin database's task is still enabled, the restored task cannot attach to the same slot
>   and enters fallback mode, reporting an error such as `Process is in error recovery (fallback mode)...`.  
>   Learn more in [One Active Consumer per Slot](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/initial-setup.md#one-active-consumer-per-slot).
>
> - Disable the task on one of the two databases (or restore with `DisableOngoingTasks = true`),  
>   or give the restored task its own slot and publication before enabling it.

> **Note**
>
> #### PostgreSQL: saved LSN no longer retained by the slot
>
> - The restored task uses the `LastLsn` saved in its `@cdc-states/<task name>` document.  
>   This works only if the PostgreSQL replication slot can still serve WAL from that position.
>
> - If the slot was dropped and recreated after the backup,
>   or if PostgreSQL no longer retains the WAL needed for the saved `LastLsn`,
>   the slot's `restart_lsn` can be ahead of the restored `LastLsn`.  
>   Changes in that gap cannot be recovered from the slot.
>
> - When this happens, CDC Sink raises a warning notification stating that the slot's restart LSN is ahead of the saved position.
>   To start over from the current source data, remove the saved CDC Sink state (`@cdc-states/<task name>`)
>   or create the task with a new name, then let the initial load run again.  
>   If the gap might include deletes, verify or rebuild the affected target documents as needed.
>
> - To avoid this gap, restore the source database and the RavenDB database to consistent points in time,  
>   and do not drop the slot while a backup that references it may still be restored.

## Behavior summary {#behavior-summary}

| Aspect | Backup / Restore behavior |
| - | - |
| Task configuration | Included in the backup; recreated on restore |
| Enabled/disabled state | Preserved from the backup, **unless** `DisableOngoingTasks = true` |
| Saved CDC progress<br />(`@cdc-states/<task name>`) | Restored as it existed in the backup; if no matching state document exists,<br />the task starts fresh unless `SkipInitialLoad` is set |
| PostgreSQL slot / publication | Not backed up; the restored task references the same names,<br />so the publication must exist and the slot must be consumable |

## See also

- [Export / Import a Task](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/export-import-task.md)
- [Enable / Disable a Task](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/enable-disable-task.md)
- [Failover and Consistency](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/failover-and-consistency.md)
