tape: allow to abort restore tasks
This commit is contained in:
parent
8de9a9917f
commit
a80d72f999
@ -25,6 +25,7 @@ use proxmox::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
task_log,
|
task_log,
|
||||||
|
task::TaskState,
|
||||||
tools::compute_file_csum,
|
tools::compute_file_csum,
|
||||||
api2::types::{
|
api2::types::{
|
||||||
DATASTORE_SCHEMA,
|
DATASTORE_SCHEMA,
|
||||||
@ -307,7 +308,7 @@ fn restore_archive<'a>(
|
|||||||
if is_new {
|
if is_new {
|
||||||
task_log!(worker, "restore snapshot {}", backup_dir);
|
task_log!(worker, "restore snapshot {}", backup_dir);
|
||||||
|
|
||||||
match restore_snapshot_archive(reader, &path) {
|
match restore_snapshot_archive(worker, reader, &path) {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
std::fs::remove_dir_all(&path)?;
|
std::fs::remove_dir_all(&path)?;
|
||||||
bail!("restore snapshot {} failed - {}", backup_dir, err);
|
bail!("restore snapshot {} failed - {}", backup_dir, err);
|
||||||
@ -367,6 +368,9 @@ fn restore_chunk_archive<'a>(
|
|||||||
|
|
||||||
let result: Result<_, Error> = proxmox::try_block!({
|
let result: Result<_, Error> = proxmox::try_block!({
|
||||||
while let Some((digest, blob)) = decoder.next_chunk()? {
|
while let Some((digest, blob)) = decoder.next_chunk()? {
|
||||||
|
|
||||||
|
worker.check_abort()?;
|
||||||
|
|
||||||
if let Some(datastore) = datastore {
|
if let Some(datastore) = datastore {
|
||||||
let chunk_exists = datastore.cond_touch_chunk(&digest, false)?;
|
let chunk_exists = datastore.cond_touch_chunk(&digest, false)?;
|
||||||
if !chunk_exists {
|
if !chunk_exists {
|
||||||
@ -413,12 +417,13 @@ fn restore_chunk_archive<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn restore_snapshot_archive<'a>(
|
fn restore_snapshot_archive<'a>(
|
||||||
|
worker: &WorkerTask,
|
||||||
reader: Box<dyn 'a + TapeRead>,
|
reader: Box<dyn 'a + TapeRead>,
|
||||||
snapshot_path: &Path,
|
snapshot_path: &Path,
|
||||||
) -> Result<bool, Error> {
|
) -> Result<bool, Error> {
|
||||||
|
|
||||||
let mut decoder = pxar::decoder::sync::Decoder::from_std(reader)?;
|
let mut decoder = pxar::decoder::sync::Decoder::from_std(reader)?;
|
||||||
match try_restore_snapshot_archive(&mut decoder, snapshot_path) {
|
match try_restore_snapshot_archive(worker, &mut decoder, snapshot_path) {
|
||||||
Ok(()) => Ok(true),
|
Ok(()) => Ok(true),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let reader = decoder.input();
|
let reader = decoder.input();
|
||||||
@ -440,6 +445,7 @@ fn restore_snapshot_archive<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn try_restore_snapshot_archive<R: pxar::decoder::SeqRead>(
|
fn try_restore_snapshot_archive<R: pxar::decoder::SeqRead>(
|
||||||
|
worker: &WorkerTask,
|
||||||
decoder: &mut pxar::decoder::sync::Decoder<R>,
|
decoder: &mut pxar::decoder::sync::Decoder<R>,
|
||||||
snapshot_path: &Path,
|
snapshot_path: &Path,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
@ -462,6 +468,8 @@ fn try_restore_snapshot_archive<R: pxar::decoder::SeqRead>(
|
|||||||
let mut manifest = None;
|
let mut manifest = None;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
worker.check_abort()?;
|
||||||
|
|
||||||
let entry = match decoder.next() {
|
let entry = match decoder.next() {
|
||||||
None => break,
|
None => break,
|
||||||
Some(entry) => entry?,
|
Some(entry) => entry?,
|
||||||
|
Loading…
Reference in New Issue
Block a user