api: admin/datastore: add new 'prune-datastore' api call

to prune the whole datastore at once, with the given parameters.
We need a new api call since this can take a while and we need to start
a worker for this. The exisiting api call returns a list of removed/kept
snapshots and is synchronous.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak
2021-07-16 10:53:26 +02:00
committed by Dietmar Maurer
parent 8e0b852f24
commit 9805207aa5
2 changed files with 69 additions and 3 deletions

View File

@ -19,9 +19,14 @@ pub fn prune_datastore(
prune_options: PruneOptions,
store: &str,
datastore: Arc<DataStore>,
dry_run: bool,
) -> Result<(), Error> {
task_log!(worker, "Starting datastore prune on store \"{}\"", store);
if dry_run {
task_log!(worker, "(dry test run)");
}
let keep_all = !prune_options.keeps_something();
if keep_all {
@ -69,7 +74,7 @@ pub fn prune_datastore(
group.backup_id(),
info.backup_dir.backup_time_string()
);
if !keep {
if !keep && !dry_run {
if let Err(err) = datastore.remove_backup_dir(&info.backup_dir, false) {
task_warn!(
worker,
@ -108,7 +113,7 @@ pub fn do_prune_job(
task_log!(worker, "task triggered by schedule '{}'", event_str);
}
let result = prune_datastore(worker.clone(), auth_id, prune_options, &store, datastore);
let result = prune_datastore(worker.clone(), auth_id, prune_options, &store, datastore, false);
let status = worker.create_state(&result);