mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-19 22:51:51 +03:00
state and dbs: backups
This commit is contained in:
parent
8e633809b4
commit
a45d14470d
@ -267,8 +267,11 @@ async fn handle_request(
|
||||
}
|
||||
}
|
||||
KvAction::Backup => {
|
||||
// loop through all db directories and backup.
|
||||
//
|
||||
// looping through open dbs and flushing their memtables
|
||||
for db_ref in open_kvs.iter() {
|
||||
let db = db_ref.value();
|
||||
db.flush()?;
|
||||
}
|
||||
(serde_json::to_vec(&KvResponse::Ok).unwrap(), None)
|
||||
}
|
||||
};
|
||||
|
@ -448,10 +448,11 @@ async fn check_caps(
|
||||
Ok(())
|
||||
}
|
||||
SqliteAction::Backup => {
|
||||
if source.process != *STATE_PROCESS_ID {
|
||||
return Err(SqliteError::NoCap {
|
||||
error: request.action.to_string(),
|
||||
});
|
||||
// flushing WALs for backup
|
||||
// check caps.
|
||||
for db_ref in open_dbs.iter() {
|
||||
let db = db_ref.value().lock().await;
|
||||
db.execute("pragma wal_checkpoint", [])?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
28
src/state.rs
28
src/state.rs
@ -218,15 +218,21 @@ async fn handle_request(
|
||||
}
|
||||
}
|
||||
StateAction::Backup => {
|
||||
// handle Backup action
|
||||
println!("got backup");
|
||||
let checkpoint_dir = format!("{}/kernel/checkpoint", &home_directory_path);
|
||||
let checkpoint_dir = format!("{}/vfs/kernel_backup", &home_directory_path);
|
||||
|
||||
if Path::new(&checkpoint_dir).exists() {
|
||||
let _ = fs::remove_dir_all(&checkpoint_dir).await;
|
||||
}
|
||||
let checkpoint = Checkpoint::new(&db).unwrap();
|
||||
checkpoint.create_checkpoint(&checkpoint_dir).unwrap();
|
||||
fs::remove_dir_all(&checkpoint_dir).await?;
|
||||
}
|
||||
let checkpoint = Checkpoint::new(&db).map_err(|e| StateError::RocksDBError {
|
||||
action: "BackupCheckpointNew".into(),
|
||||
error: e.to_string(),
|
||||
})?;
|
||||
|
||||
checkpoint.create_checkpoint(&checkpoint_dir).map_err(|e| StateError::RocksDBError {
|
||||
action: "BackupCheckpointCreate".into(),
|
||||
error: e.to_string(),
|
||||
})?;
|
||||
|
||||
(serde_json::to_vec(&StateResponse::Backup).unwrap(), None)
|
||||
}
|
||||
};
|
||||
@ -609,6 +615,14 @@ async fn get_zipped_packages() -> Vec<(String, zip::ZipArchive<std::io::Cursor<&
|
||||
packages
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for StateError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
StateError::IOError {
|
||||
error: err.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn make_error_message(our_name: String, km: &KernelMessage, error: StateError) -> KernelMessage {
|
||||
KernelMessage {
|
||||
id: km.id,
|
||||
|
Loading…
Reference in New Issue
Block a user