|
|
|
@ -13,9 +13,8 @@ |
|
|
|
|
// limitations under the License.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
use crate::{ffi, Error, DB}; |
|
|
|
|
use crate::{ffi, ffi_util::to_cpath, Error, DB}; |
|
|
|
|
|
|
|
|
|
use std::ffi::CString; |
|
|
|
|
use std::path::Path; |
|
|
|
|
|
|
|
|
|
/// Represents information of a backup including timestamp of the backup
|
|
|
|
@ -48,16 +47,7 @@ pub struct RestoreOptions { |
|
|
|
|
impl BackupEngine { |
|
|
|
|
/// Open a backup engine with the specified options.
|
|
|
|
|
pub fn open<P: AsRef<Path>>(opts: &BackupEngineOptions, path: P) -> Result<Self, Error> { |
|
|
|
|
let path = path.as_ref(); |
|
|
|
|
let cpath = if let Ok(e) = CString::new(path.to_string_lossy().as_bytes()) { |
|
|
|
|
e |
|
|
|
|
} else { |
|
|
|
|
return Err(Error::new( |
|
|
|
|
"Failed to convert path to CString \ |
|
|
|
|
when opening backup engine" |
|
|
|
|
.to_owned(), |
|
|
|
|
)); |
|
|
|
|
}; |
|
|
|
|
let cpath = to_cpath(path)?; |
|
|
|
|
|
|
|
|
|
let be: *mut ffi::rocksdb_backup_engine_t; |
|
|
|
|
unsafe { |
|
|
|
@ -136,27 +126,8 @@ impl BackupEngine { |
|
|
|
|
wal_dir: W, |
|
|
|
|
opts: &RestoreOptions, |
|
|
|
|
) -> Result<(), Error> { |
|
|
|
|
let db_dir = db_dir.as_ref(); |
|
|
|
|
let c_db_dir = if let Ok(c) = CString::new(db_dir.to_string_lossy().as_bytes()) { |
|
|
|
|
c |
|
|
|
|
} else { |
|
|
|
|
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 = if let Ok(c) = CString::new(wal_dir.to_string_lossy().as_bytes()) { |
|
|
|
|
c |
|
|
|
|
} else { |
|
|
|
|
return Err(Error::new( |
|
|
|
|
"Failed to convert wal_dir to CString \ |
|
|
|
|
when restoring from latest backup" |
|
|
|
|
.to_owned(), |
|
|
|
|
)); |
|
|
|
|
}; |
|
|
|
|
let c_db_dir = to_cpath(db_dir)?; |
|
|
|
|
let c_wal_dir = to_cpath(wal_dir)?; |
|
|
|
|
|
|
|
|
|
unsafe { |
|
|
|
|
ffi_try!(ffi::rocksdb_backup_engine_restore_db_from_latest_backup( |
|
|
|
@ -179,27 +150,8 @@ impl BackupEngine { |
|
|
|
|
opts: &RestoreOptions, |
|
|
|
|
backup_id: u32, |
|
|
|
|
) -> Result<(), Error> { |
|
|
|
|
let db_dir = db_dir.as_ref(); |
|
|
|
|
let c_db_dir = if let Ok(c) = CString::new(db_dir.to_string_lossy().as_bytes()) { |
|
|
|
|
c |
|
|
|
|
} else { |
|
|
|
|
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 = if let Ok(c) = CString::new(wal_dir.to_string_lossy().as_bytes()) { |
|
|
|
|
c |
|
|
|
|
} else { |
|
|
|
|
return Err(Error::new( |
|
|
|
|
"Failed to convert wal_dir to CString \ |
|
|
|
|
when restoring from latest backup" |
|
|
|
|
.to_owned(), |
|
|
|
|
)); |
|
|
|
|
}; |
|
|
|
|
let c_db_dir = to_cpath(db_dir)?; |
|
|
|
|
let c_wal_dir = to_cpath(wal_dir)?; |
|
|
|
|
|
|
|
|
|
unsafe { |
|
|
|
|
ffi_try!(ffi::rocksdb_backup_engine_restore_db_from_backup( |
|
|
|
|