server/prune_job: factor out 'prune_datastore'
we want to use that outside of a prune job Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
9751ef4b36
commit
61f05679d2
@ -1,6 +1,6 @@
|
|||||||
use anyhow::Error;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use proxmox::try_block;
|
use anyhow::Error;
|
||||||
|
|
||||||
use pbs_datastore::{task_log, task_warn};
|
use pbs_datastore::{task_log, task_warn};
|
||||||
|
|
||||||
@ -11,6 +11,61 @@ use crate::{
|
|||||||
server::WorkerTask,
|
server::WorkerTask,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn prune_datastore(
|
||||||
|
worker: Arc<WorkerTask>,
|
||||||
|
prune_options: PruneOptions,
|
||||||
|
store: &str,
|
||||||
|
datastore: Arc<DataStore>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
task_log!(worker, "Starting datastore prune on store \"{}\"", store);
|
||||||
|
|
||||||
|
task_log!(
|
||||||
|
worker,
|
||||||
|
"retention options: {}",
|
||||||
|
prune_options.cli_options_string()
|
||||||
|
);
|
||||||
|
|
||||||
|
let base_path = datastore.base_path();
|
||||||
|
|
||||||
|
let groups = BackupInfo::list_backup_groups(&base_path)?;
|
||||||
|
for group in groups {
|
||||||
|
let list = group.list_backups(&base_path)?;
|
||||||
|
let mut prune_info = compute_prune_info(list, &prune_options)?;
|
||||||
|
prune_info.reverse(); // delete older snapshots first
|
||||||
|
|
||||||
|
task_log!(
|
||||||
|
worker,
|
||||||
|
"Starting prune on store \"{}\" group \"{}/{}\"",
|
||||||
|
store,
|
||||||
|
group.backup_type(),
|
||||||
|
group.backup_id()
|
||||||
|
);
|
||||||
|
|
||||||
|
for (info, keep) in prune_info {
|
||||||
|
task_log!(
|
||||||
|
worker,
|
||||||
|
"{} {}/{}/{}",
|
||||||
|
if keep { "keep" } else { "remove" },
|
||||||
|
group.backup_type(),
|
||||||
|
group.backup_id(),
|
||||||
|
info.backup_dir.backup_time_string()
|
||||||
|
);
|
||||||
|
if !keep {
|
||||||
|
if let Err(err) = datastore.remove_backup_dir(&info.backup_dir, false) {
|
||||||
|
task_warn!(
|
||||||
|
worker,
|
||||||
|
"failed to remove dir {:?}: {}",
|
||||||
|
info.backup_dir.relative_path(),
|
||||||
|
err,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn do_prune_job(
|
pub fn do_prune_job(
|
||||||
mut job: Job,
|
mut job: Job,
|
||||||
prune_options: PruneOptions,
|
prune_options: PruneOptions,
|
||||||
@ -29,58 +84,11 @@ pub fn do_prune_job(
|
|||||||
move |worker| {
|
move |worker| {
|
||||||
job.start(&worker.upid().to_string())?;
|
job.start(&worker.upid().to_string())?;
|
||||||
|
|
||||||
let result = try_block!({
|
if let Some(event_str) = schedule {
|
||||||
task_log!(worker, "Starting datastore prune on store \"{}\"", store);
|
task_log!(worker, "task triggered by schedule '{}'", event_str);
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(event_str) = schedule {
|
let result = prune_datastore(worker.clone(), prune_options, &store, datastore);
|
||||||
task_log!(worker, "task triggered by schedule '{}'", event_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
task_log!(
|
|
||||||
worker,
|
|
||||||
"retention options: {}",
|
|
||||||
prune_options.cli_options_string()
|
|
||||||
);
|
|
||||||
|
|
||||||
let base_path = datastore.base_path();
|
|
||||||
|
|
||||||
let groups = BackupInfo::list_backup_groups(&base_path)?;
|
|
||||||
for group in groups {
|
|
||||||
let list = group.list_backups(&base_path)?;
|
|
||||||
let mut prune_info = compute_prune_info(list, &prune_options)?;
|
|
||||||
prune_info.reverse(); // delete older snapshots first
|
|
||||||
|
|
||||||
task_log!(
|
|
||||||
worker,
|
|
||||||
"Starting prune on store \"{}\" group \"{}/{}\"",
|
|
||||||
store,
|
|
||||||
group.backup_type(),
|
|
||||||
group.backup_id()
|
|
||||||
);
|
|
||||||
|
|
||||||
for (info, keep) in prune_info {
|
|
||||||
task_log!(
|
|
||||||
worker,
|
|
||||||
"{} {}/{}/{}",
|
|
||||||
if keep { "keep" } else { "remove" },
|
|
||||||
group.backup_type(),
|
|
||||||
group.backup_id(),
|
|
||||||
info.backup_dir.backup_time_string()
|
|
||||||
);
|
|
||||||
if !keep {
|
|
||||||
if let Err(err) = datastore.remove_backup_dir(&info.backup_dir, false) {
|
|
||||||
task_warn!(
|
|
||||||
worker,
|
|
||||||
"failed to remove dir {:?}: {}",
|
|
||||||
info.backup_dir.relative_path(),
|
|
||||||
err,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
|
|
||||||
let status = worker.create_state(&result);
|
let status = worker.create_state(&result);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user