Skip to main content

BackupEngine

Struct BackupEngine 

Source
pub struct BackupEngine { /* private fields */ }

Implementations§

Source§

impl BackupEngine

Source

pub fn open(opts: &BackupEngineOptions, env: &Env) -> Result<Self, Error>

Open a backup engine with the specified options and RocksDB Env.

Source

pub fn create_new_backup<T: ThreadMode, D: DBInner>( &mut self, db: &DBCommon<T, D>, ) -> Result<(), Error>

Captures the state of the database in the latest backup.

Note: no flush before backup is performed. User might want to use create_new_backup_flush instead.

Source

pub fn create_new_backup_flush<T: ThreadMode, D: DBInner>( &mut self, db: &DBCommon<T, D>, flush_before_backup: bool, ) -> Result<(), Error>

Captures the state of the database in the latest backup.

Set flush_before_backup=true to avoid losing unflushed key/value pairs from the memtable.

Source

pub fn create_new_backup_with_options<T: ThreadMode, D: DBInner>( &mut self, db: &DBCommon<T, D>, opts: &CreateBackupOptions, ) -> Result<u32, Error>

Captures the state of the database in the latest backup and returns the id of the new backup.

Unlike Self::create_new_backup_flush this exposes the full CreateBackupOptions surface: flush behaviour, CPU priority of the copy threads, and the progress and exclude files callbacks.

Source

pub fn create_new_backup_with_metadata<T: ThreadMode, D: DBInner>( &mut self, db: &DBCommon<T, D>, opts: &CreateBackupOptions, app_metadata: &[u8], ) -> Result<u32, Error>

Same as Self::create_new_backup_with_options but also stores application metadata with the backup, and returns the id of the new backup.

Read the metadata back with BackupEngineInfo::app_metadata.

app_metadata is passed with an explicit length and RocksDB stores it hex encoded in the backup meta file, so any byte sequence is preserved, including embedded NULs.

RocksDB rejects metadata larger than 1 MiB with an Invalid argument: App metadata too large error, and nothing is written in that case.

Source

pub fn purge_old_backups( &mut self, num_backups_to_keep: usize, ) -> Result<(), Error>

Source

pub fn restore_from_latest_backup<D: AsRef<Path>, W: AsRef<Path>>( &mut self, db_dir: D, wal_dir: W, opts: &RestoreOptions, ) -> Result<(), Error>

Restore from the latest backup

§Arguments
  • db_dir - A path to the database directory
  • wal_dir - A path to the wal directory
  • opts - Restore options
§Examples
use rust_rocksdb::backup::{BackupEngine, BackupEngineOptions};
let backup_opts = BackupEngineOptions::default();
let mut backup_engine = BackupEngine::open(&backup_opts, &backup_path).unwrap();
let mut restore_option = rust_rocksdb::backup::RestoreOptions::default();
restore_option.set_keep_log_files(true); /// true to keep log files
if let Err(e) = backup_engine.restore_from_latest_backup(&db_path, &wal_dir, &restore_option) {
    error!("Failed to restore from the backup. Error: {:?}", e);
    return Err(e.to_string());
}
Source

pub fn restore_from_backup<D: AsRef<Path>, W: AsRef<Path>>( &mut self, db_dir: D, wal_dir: W, opts: &RestoreOptions, backup_id: u32, ) -> Result<(), Error>

Restore from a specified backup

The specified backup id should be passed in as an additional parameter.

Source

pub fn verify_backup(&self, backup_id: u32) -> Result<(), Error>

Checks that each file exists and that the size of the file matches our expectations. it does not check file checksum.

If this BackupEngine created the backup, it compares the files’ current sizes against the number of bytes written to them during creation. Otherwise, it compares the files’ current sizes against their sizes when the BackupEngine was opened.

Source

pub fn get_backup_info(&self) -> Vec<BackupEngineInfo>

Get a list of all backups together with information on timestamp of the backup and the size (please note that sum of all backups’ sizes is bigger than the actual size of the backup directory because some data is shared by multiple backups). Backups are identified by their always-increasing IDs.

You can perform this function safely, even with other BackupEngine performing backups on the same directory

Source

pub fn stop_backup(&mut self)

Aborts a backup that is currently running.

This is one way. Once it is called on a backup engine, every later backup request on that engine fails. The backup directory is left consistent and is cleaned up by the next backup or garbage collection performed through a new backup engine on the same directory.

Trait Implementations§

Source§

impl Drop for BackupEngine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for BackupEngine

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.