manager: hidden command to move datastore prune opts into jobs
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
@ -251,22 +251,22 @@ pub fn update_datastore(
|
||||
data.prune_schedule = None;
|
||||
}
|
||||
DeletableProperty::keep_last => {
|
||||
data.keep_last = None;
|
||||
data.keep.keep_last = None;
|
||||
}
|
||||
DeletableProperty::keep_hourly => {
|
||||
data.keep_hourly = None;
|
||||
data.keep.keep_hourly = None;
|
||||
}
|
||||
DeletableProperty::keep_daily => {
|
||||
data.keep_daily = None;
|
||||
data.keep.keep_daily = None;
|
||||
}
|
||||
DeletableProperty::keep_weekly => {
|
||||
data.keep_weekly = None;
|
||||
data.keep.keep_weekly = None;
|
||||
}
|
||||
DeletableProperty::keep_monthly => {
|
||||
data.keep_monthly = None;
|
||||
data.keep.keep_monthly = None;
|
||||
}
|
||||
DeletableProperty::keep_yearly => {
|
||||
data.keep_yearly = None;
|
||||
data.keep.keep_yearly = None;
|
||||
}
|
||||
DeletableProperty::verify_new => {
|
||||
data.verify_new = None;
|
||||
@ -308,23 +308,23 @@ pub fn update_datastore(
|
||||
data.prune_schedule = update.prune_schedule;
|
||||
}
|
||||
|
||||
if update.keep_last.is_some() {
|
||||
data.keep_last = update.keep_last;
|
||||
if update.keep.keep_last.is_some() {
|
||||
data.keep.keep_last = update.keep.keep_last;
|
||||
}
|
||||
if update.keep_hourly.is_some() {
|
||||
data.keep_hourly = update.keep_hourly;
|
||||
if update.keep.keep_hourly.is_some() {
|
||||
data.keep.keep_hourly = update.keep.keep_hourly;
|
||||
}
|
||||
if update.keep_daily.is_some() {
|
||||
data.keep_daily = update.keep_daily;
|
||||
if update.keep.keep_daily.is_some() {
|
||||
data.keep.keep_daily = update.keep.keep_daily;
|
||||
}
|
||||
if update.keep_weekly.is_some() {
|
||||
data.keep_weekly = update.keep_weekly;
|
||||
if update.keep.keep_weekly.is_some() {
|
||||
data.keep.keep_weekly = update.keep.keep_weekly;
|
||||
}
|
||||
if update.keep_monthly.is_some() {
|
||||
data.keep_monthly = update.keep_monthly;
|
||||
if update.keep.keep_monthly.is_some() {
|
||||
data.keep.keep_monthly = update.keep.keep_monthly;
|
||||
}
|
||||
if update.keep_yearly.is_some() {
|
||||
data.keep_yearly = update.keep_yearly;
|
||||
if update.keep.keep_yearly.is_some() {
|
||||
data.keep.keep_yearly = update.keep.keep_yearly;
|
||||
}
|
||||
|
||||
if let Some(notify_str) = update.notify {
|
||||
|
@ -453,6 +453,9 @@ async fn run() -> Result<(), Error> {
|
||||
.insert("versions", CliCommand::new(&API_METHOD_GET_VERSIONS));
|
||||
|
||||
let args: Vec<String> = std::env::args().take(2).collect();
|
||||
if args.len() >= 2 && args[1] == "update-to-prune-jobs-config" {
|
||||
return update_to_prune_jobs_config();
|
||||
}
|
||||
let avoid_init = args.len() >= 2 && (args[1] == "bashcomplete" || args[1] == "printdoc");
|
||||
|
||||
if !avoid_init {
|
||||
@ -460,6 +463,7 @@ async fn run() -> Result<(), Error> {
|
||||
let file_opts = CreateOptions::new()
|
||||
.owner(backup_user.uid)
|
||||
.group(backup_user.gid);
|
||||
|
||||
proxmox_rest_server::init_worker_tasks(
|
||||
pbs_buildcfg::PROXMOX_BACKUP_LOG_DIR_M!().into(),
|
||||
file_opts,
|
||||
|
@ -47,8 +47,8 @@ use pbs_buildcfg::configdir;
|
||||
use proxmox_time::CalendarEvent;
|
||||
|
||||
use pbs_api_types::{
|
||||
Authid, DataStoreConfig, KeepOptions, Operation, PruneJobConfig, PruneJobOptions,
|
||||
SyncJobConfig, TapeBackupJobConfig, VerificationJobConfig,
|
||||
Authid, DataStoreConfig, Operation, PruneJobConfig, PruneJobOptions, SyncJobConfig,
|
||||
TapeBackupJobConfig, VerificationJobConfig,
|
||||
};
|
||||
|
||||
use proxmox_rest_server::daemon;
|
||||
@ -692,14 +692,7 @@ async fn schedule_datastore_prune() {
|
||||
};
|
||||
|
||||
let prune_options = PruneJobOptions {
|
||||
keep: KeepOptions {
|
||||
keep_last: store_config.keep_last,
|
||||
keep_hourly: store_config.keep_hourly,
|
||||
keep_daily: store_config.keep_daily,
|
||||
keep_weekly: store_config.keep_weekly,
|
||||
keep_monthly: store_config.keep_monthly,
|
||||
keep_yearly: store_config.keep_yearly,
|
||||
},
|
||||
keep: store_config.keep,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Error;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
|
||||
use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
|
||||
use proxmox_schema::api;
|
||||
|
||||
use pbs_api_types::{PruneJobConfig, JOB_ID_SCHEMA};
|
||||
use pbs_api_types::{DataStoreConfig, PruneJobConfig, PruneJobOptions, JOB_ID_SCHEMA};
|
||||
use pbs_config::prune;
|
||||
|
||||
use proxmox_backup::api2;
|
||||
@ -155,3 +156,77 @@ fn get_prune_job(id: &str) -> Result<PruneJobConfig, Error> {
|
||||
|
||||
config.lookup("prune", id)
|
||||
}
|
||||
|
||||
pub(crate) fn update_to_prune_jobs_config() -> Result<(), Error> {
|
||||
use pbs_config::datastore;
|
||||
|
||||
let _prune_lock = prune::lock_config()?;
|
||||
let _datastore_lock = datastore::lock_config()?;
|
||||
|
||||
let (mut data, _digest) = prune::config()?;
|
||||
let (mut storeconfig, _digest) = datastore::config()?;
|
||||
|
||||
for (store, entry) in storeconfig.sections.iter_mut() {
|
||||
let ty = &entry.0;
|
||||
|
||||
if ty != "datastore" {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut config = match DataStoreConfig::deserialize(&entry.1) {
|
||||
Ok(c) => c,
|
||||
Err(err) => {
|
||||
eprintln!("failed to parse config of store {store}: {err}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let options = PruneJobOptions {
|
||||
keep: std::mem::take(&mut config.keep),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let schedule = config.prune_schedule.take();
|
||||
|
||||
entry.1 = serde_json::to_value(config)?;
|
||||
|
||||
let schedule = match schedule {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
eprintln!("dropping disabled prune job in datastore.cfg");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let mut id = format!("storeconfig-{store}");
|
||||
id.truncate(32);
|
||||
if data.sections.contains_key(&id) {
|
||||
eprintln!("skipping existing converted prune job: {id}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if !options.keeps_something() {
|
||||
eprintln!("dropping empty prune job data in datastore.cfg");
|
||||
continue;
|
||||
}
|
||||
|
||||
let prune_config = PruneJobConfig {
|
||||
id: id.clone(),
|
||||
store: store.clone(),
|
||||
disable: false,
|
||||
comment: None,
|
||||
schedule,
|
||||
options,
|
||||
};
|
||||
|
||||
let prune_config = serde_json::to_value(prune_config)?;
|
||||
|
||||
data.sections
|
||||
.insert(id, ("prune".to_string(), prune_config));
|
||||
}
|
||||
|
||||
prune::save_config(&data)?;
|
||||
datastore::save_config(&storeconfig)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user