diff --git a/pbs-config/src/lib.rs b/pbs-config/src/lib.rs index a0dd9298..301f4b59 100644 --- a/pbs-config/src/lib.rs +++ b/pbs-config/src/lib.rs @@ -3,6 +3,7 @@ pub mod drive; pub mod key_config; pub mod media_pool; pub mod remote; +pub mod sync; pub mod tape_encryption_keys; pub mod tape_job; diff --git a/src/config/sync.rs b/pbs-config/src/sync.rs similarity index 85% rename from src/config/sync.rs rename to pbs-config/src/sync.rs index 7fd5e34a..63b30c94 100644 --- a/src/config/sync.rs +++ b/pbs-config/src/sync.rs @@ -13,6 +13,8 @@ use proxmox::api::{ use pbs_api_types::{JOB_ID_SCHEMA, SyncJobConfig}; +use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; + lazy_static! { pub static ref CONFIG: SectionConfig = init(); } @@ -34,6 +36,11 @@ fn init() -> SectionConfig { pub const SYNC_CFG_FILENAME: &str = "/etc/proxmox-backup/sync.cfg"; pub const SYNC_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.sync.lck"; +/// Get exclusive lock +pub fn lock_config() -> Result { + open_backup_lockfile(SYNC_CFG_LOCKFILE, None, true) +} + pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> { let content = proxmox::tools::fs::file_read_optional_string(SYNC_CFG_FILENAME)? @@ -46,7 +53,7 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> { pub fn save_config(config: &SectionConfigData) -> Result<(), Error> { let raw = CONFIG.write(SYNC_CFG_FILENAME, &config)?; - pbs_config::replace_backup_config(SYNC_CFG_FILENAME, raw.as_bytes()) + replace_backup_config(SYNC_CFG_FILENAME, raw.as_bytes()) } // shell completion helper diff --git a/src/api2/admin/sync.rs b/src/api2/admin/sync.rs index 943e81fd..83d5c05d 100644 --- a/src/api2/admin/sync.rs +++ b/src/api2/admin/sync.rs @@ -8,6 +8,7 @@ use proxmox::api::router::SubdirMap; use proxmox::{list_subdirs_api_method, sortable}; use pbs_api_types::{DATASTORE_SCHEMA, JOB_ID_SCHEMA, Authid, SyncJobConfig, SyncJobStatus}; +use pbs_config::sync; use crate::{ api2::{ @@ -19,7 +20,6 @@ use crate::{ }, config::{ cached_user_info::CachedUserInfo, - sync, }, server::{ jobstate::{ diff --git a/src/api2/config/remote.rs b/src/api2/config/remote.rs index 81b85a20..df91c4c8 100644 --- a/src/api2/config/remote.rs +++ b/src/api2/config/remote.rs @@ -10,10 +10,10 @@ use pbs_api_types::{ REMOTE_ID_SCHEMA, REMOTE_PASSWORD_SCHEMA, Remote, RemoteConfig, RemoteConfigUpdater, Authid, PROXMOX_CONFIG_DIGEST_SCHEMA, DataStoreListItem, SyncJobConfig, }; +use pbs_config::sync; use crate::config::cached_user_info::CachedUserInfo; use crate::config::acl::{PRIV_REMOTE_AUDIT, PRIV_REMOTE_MODIFY}; -use crate::config::sync; #[api( input: { diff --git a/src/api2/config/sync.rs b/src/api2/config/sync.rs index 00a2eb75..4a4df6f9 100644 --- a/src/api2/config/sync.rs +++ b/src/api2/config/sync.rs @@ -9,6 +9,7 @@ use pbs_api_types::{ SINGLE_LINE_COMMENT_SCHEMA, JOB_ID_SCHEMA, REMOTE_ID_SCHEMA, DATASTORE_SCHEMA, REMOVE_VANISHED_BACKUPS_SCHEMA, SYNC_SCHEDULE_SCHEMA, PROXMOX_CONFIG_DIGEST_SCHEMA, }; +use pbs_config::sync; use crate::config::acl::{ PRIV_DATASTORE_AUDIT, @@ -19,8 +20,7 @@ use crate::config::acl::{ PRIV_REMOTE_READ, }; -use crate::config::{sync, cached_user_info::CachedUserInfo}; -use pbs_config::open_backup_lockfile; +use crate::config::cached_user_info::CachedUserInfo; pub fn check_sync_job_read_access( user_info: &CachedUserInfo, @@ -155,7 +155,7 @@ pub fn create_sync_job( let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let user_info = CachedUserInfo::new()?; - let _lock = open_backup_lockfile(sync::SYNC_CFG_LOCKFILE, None, true)?; + let _lock = sync::lock_config()?; let sync_job: SyncJobConfig = serde_json::from_value(param)?; if !check_sync_job_modify_access(&user_info, &auth_id, &sync_job) { @@ -299,7 +299,7 @@ pub fn update_sync_job( let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let user_info = CachedUserInfo::new()?; - let _lock = open_backup_lockfile(sync::SYNC_CFG_LOCKFILE, None, true)?; + let _lock = sync::lock_config()?; // pass/compare digest let (mut config, expected_digest) = sync::config()?; @@ -382,7 +382,7 @@ pub fn delete_sync_job( let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let user_info = CachedUserInfo::new()?; - let _lock = open_backup_lockfile(sync::SYNC_CFG_LOCKFILE, None, true)?; + let _lock = sync::lock_config()?; let (mut config, expected_digest) = sync::config()?; diff --git a/src/bin/docgen.rs b/src/bin/docgen.rs index d8a8cc0c..2767c570 100644 --- a/src/bin/docgen.rs +++ b/src/bin/docgen.rs @@ -59,7 +59,7 @@ fn main() -> Result<(), Error> { "tape-job.cfg" => dump_section_config(&pbs_config::tape_job::CONFIG), "user.cfg" => dump_section_config(&config::user::CONFIG), "remote.cfg" => dump_section_config(&pbs_config::remote::CONFIG), - "sync.cfg" => dump_section_config(&config::sync::CONFIG), + "sync.cfg" => dump_section_config(&pbs_config::sync::CONFIG), "verification.cfg" => dump_section_config(&config::verify::CONFIG), "media-pool.cfg" => dump_section_config(&pbs_config::media_pool::CONFIG), "config::acl::Role" => dump_enum_properties(&config::acl::Role::API_SCHEMA)?, diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index bb4d6da6..f34008cf 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -521,7 +521,7 @@ async fn schedule_datastore_prune() { async fn schedule_datastore_sync_jobs() { - let config = match proxmox_backup::config::sync::config() { + let config = match pbs_config::sync::config() { Err(err) => { eprintln!("unable to read sync job config - {}", err); return; diff --git a/src/bin/proxmox_backup_manager/sync.rs b/src/bin/proxmox_backup_manager/sync.rs index c93ef294..6b3e91bc 100644 --- a/src/bin/proxmox_backup_manager/sync.rs +++ b/src/bin/proxmox_backup_manager/sync.rs @@ -77,12 +77,12 @@ pub fn sync_job_commands() -> CommandLineInterface { .insert("show", CliCommand::new(&API_METHOD_SHOW_SYNC_JOB) .arg_param(&["id"]) - .completion_cb("id", config::sync::complete_sync_job_id) + .completion_cb("id", pbs_config::sync::complete_sync_job_id) ) .insert("create", CliCommand::new(&api2::config::sync::API_METHOD_CREATE_SYNC_JOB) .arg_param(&["id"]) - .completion_cb("id", config::sync::complete_sync_job_id) + .completion_cb("id", pbs_config::sync::complete_sync_job_id) .completion_cb("schedule", config::datastore::complete_calendar_event) .completion_cb("store", config::datastore::complete_datastore_name) .completion_cb("remote", pbs_config::remote::complete_remote_name) @@ -91,7 +91,7 @@ pub fn sync_job_commands() -> CommandLineInterface { .insert("update", CliCommand::new(&api2::config::sync::API_METHOD_UPDATE_SYNC_JOB) .arg_param(&["id"]) - .completion_cb("id", config::sync::complete_sync_job_id) + .completion_cb("id", pbs_config::sync::complete_sync_job_id) .completion_cb("schedule", config::datastore::complete_calendar_event) .completion_cb("store", config::datastore::complete_datastore_name) .completion_cb("remote-store", crate::complete_remote_datastore_name) @@ -99,7 +99,7 @@ pub fn sync_job_commands() -> CommandLineInterface { .insert("remove", CliCommand::new(&api2::config::sync::API_METHOD_DELETE_SYNC_JOB) .arg_param(&["id"]) - .completion_cb("id", config::sync::complete_sync_job_id) + .completion_cb("id", pbs_config::sync::complete_sync_job_id) ); cmd_def.into() diff --git a/src/config/mod.rs b/src/config/mod.rs index 45b6254e..036b61e8 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -20,7 +20,6 @@ pub mod cached_user_info; pub mod datastore; pub mod network; pub mod node; -pub mod sync; pub mod tfa; pub mod token_shadow; pub mod user;