Fix/backups (#2659)

* fix master build (#2639)

* feat: Change ts to use rsync
Chore: Update the ts to use types over interface

* feat: Get the rust and the js to do a backup

* Wip: Got the backup working?

* fix permissions

* remove trixie list

* update tokio to fix timer bug

* fix error handling on backup

* wip

* remove idmap

* run restore before init, and init with own version on restore

---------

Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>
Co-authored-by: Aiden McClelland <me@drbonez.dev>
This commit is contained in:
Jade
2024-07-17 15:46:27 -06:00
committed by GitHub
parent 95611e9c4b
commit 8f0bdcd172
23 changed files with 445 additions and 380 deletions

View File

@@ -1,5 +1,7 @@
use std::path::PathBuf;
use std::sync::Arc;
use futures::future::BoxFuture;
use futures::FutureExt;
use models::ProcedureName;
@@ -19,7 +21,7 @@ pub(in crate::service) struct Backup {
pub path: PathBuf,
}
impl Handler<Backup> for ServiceActor {
type Response = Result<(), Error>;
type Response = Result<BoxFuture<'static, Result<(), Error>>, Error>;
fn conflicts_with(_: &Backup) -> ConflictBuilder<Self> {
ConflictBuilder::everything()
.except::<GetConfig>()
@@ -37,43 +39,31 @@ impl Handler<Backup> for ServiceActor {
let path = backup.path.clone();
let seed = self.0.clone();
let state = self.0.persistent_container.state.clone();
let transition = RemoteCancellable::new(
async move {
temp.stop();
let transition = RemoteCancellable::new(async move {
temp.stop();
current
.wait_for(|s| s.running_status.is_none())
.await
.with_kind(ErrorKind::Unknown)?;
let backup_guard = seed
.persistent_container
.mount_backup(path, ReadWrite)
.await?;
seed.persistent_container
.execute(id, ProcedureName::CreateBackup, Value::Null, None)
.await?;
backup_guard.unmount(true).await?;
if temp.restore().is_start() {
current
.wait_for(|s| s.running_status.is_none())
.wait_for(|s| s.running_status.is_some())
.await
.with_kind(ErrorKind::Unknown)?;
let backup_guard = seed
.persistent_container
.mount_backup(path, ReadWrite)
.await?;
seed.persistent_container
.execute(id, ProcedureName::CreateBackup, Value::Null, None)
.await?;
backup_guard.unmount(true).await?;
if temp.restore().is_start() {
current
.wait_for(|s| s.running_status.is_some())
.await
.with_kind(ErrorKind::Unknown)?;
}
drop(temp);
state.send_modify(|s| {
s.transition_state.take();
});
Ok::<_, Error>(())
}
.map(|x| {
if let Err(err) = dbg!(x) {
tracing::debug!("{:?}", err);
tracing::warn!("{}", err);
}
}),
);
drop(temp);
Ok::<_, Arc<Error>>(())
});
let cancel_handle = transition.cancellation_handle();
let transition = transition.shared();
let job_transition = transition.clone();
@@ -92,9 +82,11 @@ impl Handler<Backup> for ServiceActor {
if let Some(t) = old {
t.abort().await;
}
match transition.await {
None => Err(Error::new(eyre!("Backup canceled"), ErrorKind::Unknown)),
Some(x) => Ok(x),
}
Ok(transition
.map(|r| {
r.ok_or_else(|| Error::new(eyre!("Backup canceled"), ErrorKind::Cancelled))?
.map_err(|e| e.clone_output())
})
.boxed())
}
}

View File

@@ -79,7 +79,10 @@ impl TempDesiredRestore {
}
impl Drop for TempDesiredRestore {
fn drop(&mut self) {
self.0.send_modify(|s| s.temp_desired_state = None);
self.0.send_modify(|s| {
s.temp_desired_state.take();
s.transition_state.take();
});
}
}
// impl Deref for TempDesiredState {