Skip to main content
BackupEngine provides APIs for creating and managing consistent backups of RocksDB databases. It supports incremental backups, backup verification, and flexible restore options.

Opening a BackupEngine

Open

Opens a BackupEngine with the specified options.
const BackupEngineOptions&
Configuration for the backup engine including backup directory and sharing options.
Env*
Environment used by the database being backed up.
BackupEngine**
Output parameter for the opened BackupEngine.
IOStatus
Returns OK on success.

Creating Backups

CreateNewBackup

Captures the state of the database by creating a new backup.
const CreateBackupOptions&
Options including whether to flush before backup and progress callback.
DB*
Database to back up.
BackupID*
Optional output parameter for the new backup’s ID.
IOStatus
Returns OK on success.

CreateNewBackupWithMetadata

Creates a backup with application-specific metadata.

Backup Management

GetBackupInfo

Retrieves information about all non-corrupt backups.
std::vector<BackupInfo>*
Output vector of backup information.
bool
If true, includes detailed file information for each backup.

GetLatestBackupInfo

Retrieves information about the latest good backup.

DeleteBackup

Deletes a specific backup.
BackupID
ID of the backup to delete.

PurgeOldBackups

Deletes old backups, keeping only the specified number of latest backups.

GarbageCollect

Deletes files left over from incomplete backup operations.

Restoring Backups

RestoreDBFromBackup

Restores a database from a specific backup.
const RestoreOptions&
Restore options including incremental restore mode.
BackupID
ID of the backup to restore.
const std::string&
Target directory for database files.
const std::string&
Target directory for WAL files.
IOStatus
Returns OK on success.

RestoreDBFromLatestBackup

Restores from the latest non-corrupt backup.

Backup Verification

VerifyBackup

Verifies a backup’s integrity.
BackupID
ID of the backup to verify.
bool
If true, verifies file checksums. If false, only checks file existence and size.

Configuration

BackupEngineOptions

std::string
Directory where backups are stored. Required.
bool
If true, table and blob files are shared among backups for space savings and incremental backups.
bool
If true, guarantees consistent backup/restore even on machine crash.
uint64_t
Max bytes per second during backup. 0 means unlimited.
int
Number of threads for parallel backup/restore operations.

CreateBackupOptions

bool
Whether to flush memtable before backup. Always triggered if 2PC is enabled.
std::function<void()>
Callback for progress reporting based on callback_trigger_interval_size.
std::function
Advanced callback to exclude shared files from backup.

RestoreOptions

Mode
Restore strategy: kKeepLatestDbSessionIdFiles (incremental), kVerifyChecksum (verify then restore), or kPurgeAllFiles (full restore).
bool
If true, don’t overwrite existing log files.

BackupInfo Structure

BackupID
Unique identifier for the backup.
int64_t
Creation time from GetCurrentTime.
uint64_t
Total size in bytes.
std::string
Application-specific metadata.

Example: Creating and Restoring Backups

File Sharing and Naming

ShareFilesNaming

ShareFilesNaming
Recommended. Uses file_number and db_session_id for unique file naming.
ShareFilesNaming
Legacy naming using CRC32c and file size. Only for preserving old behavior.

Stopping Backups

StopBackup

Stops an in-progress backup. The backup will stop ASAP and return Status::Incomplete(). This is a one-way operation - to create new backups, open a new BackupEngine.

See Also