issue#135 Expose API to restore database from backups

master
Rohit Joshi 5 years ago
parent 1038c71df8
commit e3aef69f38
  1. 54
      src/backup.rs

@ -78,6 +78,60 @@ impl BackupEngine {
Ok(())
}
}
/// Restore from the latest backup
/// db_dir: input db directory
/// wal_dir: input wal directory
/// opts: restore options
/// example:
/// use rocksdb::backup::{BackupEngine, BackupEngineOptions};
/// let backup_opts = BackupEngineOptions::default();
/// let backup_engine = BackupEngine::open(&backup_opts, &backup_path).unwrap();
/// let mut restore_option = 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());
/// }
pub fn restore_from_latest_backup<P: AsRef<Path>>(
&mut self,
db_dir: P,
wal_dir: P,
opts: &RestoreOptions,
) -> Result<(), Error> {
let db_dir = db_dir.as_ref();
let c_db_dir = match CString::new(db_dir.to_string_lossy().as_bytes()) {
Ok(c) => c,
Err(_) => {
return Err(Error::new(
"Failed to convert db_dir to CString \
when restoring from latest backup"
.to_owned(),
));
}
};
let wal_dir = wal_dir.as_ref();
let c_wal_dir = match CString::new(wal_dir.to_string_lossy().as_bytes()) {
Ok(c) => c,
Err(_) => {
return Err(Error::new(
"Failed to convert wal_dir to CString \
when restoring from latest backup"
.to_owned(),
));
}
};
unsafe {
ffi_try!(ffi::rocksdb_backup_engine_restore_db_from_latest_backup(
self.inner,
c_db_dir.as_ptr(),
c_wal_dir.as_ptr(),
opts.inner,
));
}
Ok(())
}
}
impl BackupEngineOptions {

Loading…
Cancel
Save