* [pbs-devel] [PATCH proxmox v3 1/1] pbs-api-types: add 'unmount-on-done' field to sync job config
2025-11-12 12:05 [pbs-devel] [PATCH proxmox{, -backup} v3 0/5] unmount datastores after sync job Hannes Laimer
@ 2025-11-12 12:05 ` Hannes Laimer
2025-11-14 21:36 ` [pbs-devel] applied: " Thomas Lamprecht
2025-11-12 12:05 ` [pbs-devel] [PATCH proxmox-backup v3 1/4] api: syncjob: correctly update/delete 'unmount-on-done' field Hannes Laimer
` (4 subsequent siblings)
5 siblings, 1 reply; 8+ messages in thread
From: Hannes Laimer @ 2025-11-12 12:05 UTC (permalink / raw)
To: pbs-devel
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
pbs-api-types/src/jobs.rs | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/pbs-api-types/src/jobs.rs b/pbs-api-types/src/jobs.rs
index 4dbbef2b..2e3c1c62 100644
--- a/pbs-api-types/src/jobs.rs
+++ b/pbs-api-types/src/jobs.rs
@@ -538,6 +538,9 @@ pub const SYNC_VERIFIED_ONLY_SCHEMA: Schema =
BooleanSchema::new("Only synchronize verified backup snapshots, exclude others.").schema();
pub const RUN_SYNC_ON_MOUNT_SCHEMA: Schema =
BooleanSchema::new("Run this job when a relevant datastore is mounted.").schema();
+pub const UNMOUNT_ON_SYNC_DONE_SCHEMA: Schema =
+ BooleanSchema::new("Unmount involved removable datastore after the sync job finishes. Requires 'run-on-mount' to be enabled.")
+ .schema();
#[api(
properties: {
@@ -609,6 +612,10 @@ pub const RUN_SYNC_ON_MOUNT_SCHEMA: Schema =
schema: RUN_SYNC_ON_MOUNT_SCHEMA,
optional: true,
},
+ "unmount-on-done": {
+ schema: UNMOUNT_ON_SYNC_DONE_SCHEMA,
+ optional: true,
+ },
"sync-direction": {
type: SyncDirection,
optional: true,
@@ -655,6 +662,8 @@ pub struct SyncJobConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub run_on_mount: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
+ pub unmount_on_done: Option<bool>,
+ #[serde(skip_serializing_if = "Option::is_none")]
pub sync_direction: Option<SyncDirection>,
}
--
2.47.3
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* [pbs-devel] [PATCH proxmox-backup v3 1/4] api: syncjob: correctly update/delete 'unmount-on-done' field
2025-11-12 12:05 [pbs-devel] [PATCH proxmox{, -backup} v3 0/5] unmount datastores after sync job Hannes Laimer
2025-11-12 12:05 ` [pbs-devel] [PATCH proxmox v3 1/1] pbs-api-types: add 'unmount-on-done' field to sync job config Hannes Laimer
@ 2025-11-12 12:05 ` Hannes Laimer
2025-11-12 12:05 ` [pbs-devel] [PATCH proxmox-backup v3 2/4] api: datastore: auto-unmount after mount-triggered sync Hannes Laimer
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Hannes Laimer @ 2025-11-12 12:05 UTC (permalink / raw)
To: pbs-devel
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
src/api2/config/sync.rs | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/api2/config/sync.rs b/src/api2/config/sync.rs
index 358409b5..dff447cb 100644
--- a/src/api2/config/sync.rs
+++ b/src/api2/config/sync.rs
@@ -341,6 +341,8 @@ pub enum DeletableProperty {
VerifiedOnly,
/// Delete the run_on_mount property,
RunOnMount,
+ /// Delete the unmount_on_done property,
+ UnmountOnDone,
/// Delete the sync_direction property,
SyncDirection,
}
@@ -463,6 +465,9 @@ pub fn update_sync_job(
DeletableProperty::RunOnMount => {
data.run_on_mount = None;
}
+ DeletableProperty::UnmountOnDone => {
+ data.unmount_on_done = None;
+ }
DeletableProperty::SyncDirection => {
data.sync_direction = None;
}
@@ -515,6 +520,12 @@ pub fn update_sync_job(
if let Some(run_on_mount) = update.run_on_mount {
data.run_on_mount = Some(run_on_mount);
}
+ if let Some(unmount_on_done) = update.unmount_on_done {
+ if unmount_on_done && data.run_on_mount != Some(true) {
+ bail!("'unmount-on-done' can only be set when 'run-on-mount' is enabled");
+ }
+ data.unmount_on_done = Some(unmount_on_done);
+ }
if let Some(sync_direction) = update.sync_direction {
data.sync_direction = Some(sync_direction);
}
@@ -692,6 +703,7 @@ acl:1:/remote/remote1/remotestore1:write@pbs:RemoteSyncOperator
encrypted_only: None,
verified_only: None,
run_on_mount: None,
+ unmount_on_done: None,
sync_direction: None, // use default
};
--
2.47.3
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* [pbs-devel] [PATCH proxmox-backup v3 2/4] api: datastore: auto-unmount after mount-triggered sync
2025-11-12 12:05 [pbs-devel] [PATCH proxmox{, -backup} v3 0/5] unmount datastores after sync job Hannes Laimer
2025-11-12 12:05 ` [pbs-devel] [PATCH proxmox v3 1/1] pbs-api-types: add 'unmount-on-done' field to sync job config Hannes Laimer
2025-11-12 12:05 ` [pbs-devel] [PATCH proxmox-backup v3 1/4] api: syncjob: correctly update/delete 'unmount-on-done' field Hannes Laimer
@ 2025-11-12 12:05 ` Hannes Laimer
2025-11-12 12:05 ` [pbs-devel] [PATCH proxmox-backup v3 3/4] ui: add 'unmount-on-done' field to SyncJobEdit window Hannes Laimer
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Hannes Laimer @ 2025-11-12 12:05 UTC (permalink / raw)
To: pbs-devel
When a datastore mount triggers sync jobs, unmount the datastore afterwards
if any such job has unmount_on_done=true. This applies only to mount-triggered
runs. Manual and scheduled syncs run in the proxy and cannot perform the
privileged unmount.
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
src/api2/admin/datastore.rs | 96 ++++++++++++++++++++++---------------
1 file changed, 57 insertions(+), 39 deletions(-)
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 6e269ef9..911378d7 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -2454,6 +2454,7 @@ async fn do_sync_jobs(
}
}
}
+
Ok(())
}
@@ -2515,30 +2516,44 @@ pub fn mount(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Er
warn!("unable to parse sync job config, won't run any sync jobs");
return Ok(());
};
- let mut jobs_to_run: Vec<SyncJobConfig> = list
- .into_iter()
- .filter(|job: &SyncJobConfig| {
- // add job iff (running on mount is enabled and) any of these apply
- // - the jobs is local and we are source or target
- // - we are the source of a push to a remote
- // - we are the target of a pull from a remote
- //
- // `job.store == datastore.name` iff we are the target for pull from remote or we
- // are the source for push to remote, therefore we don't have to check for the
- // direction of the job.
- job.run_on_mount.unwrap_or(false)
- && (job.remote.is_none() && job.remote_store == name || job.store == name)
- })
- .collect();
+ let (unmount_on_done, mut jobs_to_run): (bool, Vec<SyncJobConfig>) =
+ list.into_iter().fold(
+ (false, Vec::new()),
+ |(mut unmount, mut jobs), job: SyncJobConfig| {
+ // add job iff (running on mount is enabled and) any of these apply
+ // - the jobs is local and we are source or target
+ // - we are the source of a push to a remote
+ // - we are the target of a pull from a remote
+ //
+ // `job.store == datastore.name` iff we are the target for pull from remote or we
+ // are the source for push to remote, therefore we don't have to check for the
+ // direction of the job.
+ let should_run = job.run_on_mount.unwrap_or(false)
+ && (job.remote.is_none() && job.remote_store == name
+ || job.store == name);
+ if should_run {
+ unmount |= job.unmount_on_done.unwrap_or_default();
+ jobs.push(job);
+ };
+ (unmount, jobs)
+ },
+ );
jobs_to_run.sort_by(|j1, j2| j1.id.cmp(&j2.id));
if !jobs_to_run.is_empty() {
info!("starting {} sync jobs", jobs_to_run.len());
let _ = WorkerTask::spawn(
"mount-sync-jobs",
- Some(store),
+ Some(store.clone()),
auth_id.to_string(),
false,
- move |worker| async move { do_sync_jobs(jobs_to_run, worker).await },
+ move |worker| async move {
+ let res = do_sync_jobs(jobs_to_run, worker).await;
+ if unmount_on_done {
+ info!("start unmounting...");
+ do_unmount(store, auth_id, false).await?;
+ }
+ res
+ },
);
}
Ok(())
@@ -2624,25 +2639,7 @@ fn do_unmount_device(
Ok(())
}
-#[api(
- protected: true,
- input: {
- properties: {
- store: { schema: DATASTORE_SCHEMA },
- },
- },
- returns: {
- schema: UPID_SCHEMA,
- },
- access: {
- permission: &Permission::And(&[
- &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_MODIFY, true),
- &Permission::Privilege(&["system", "disks"], PRIV_SYS_MODIFY, false)
- ]),
- }
-)]
-/// Unmount a removable device that is associated with the datastore
-pub async fn unmount(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
+async fn do_unmount(store: String, auth_id: Authid, to_stdout: bool) -> Result<Value, Error> {
let _lock = pbs_config::datastore::lock_config()?;
let (mut section_config, _digest) = pbs_config::datastore::config()?;
let mut datastore: DataStoreConfig = section_config.lookup("datastore", &store)?;
@@ -2662,9 +2659,6 @@ pub async fn unmount(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result<V
drop(_lock);
- let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
- let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
-
if let Ok(proxy_pid) = proxmox_rest_server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)
{
let sock = proxmox_daemon::command_socket::path_from_pid(proxy_pid);
@@ -2689,6 +2683,30 @@ pub async fn unmount(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result<V
Ok(json!(upid))
}
+#[api(
+ protected: true,
+ input: {
+ properties: {
+ store: { schema: DATASTORE_SCHEMA },
+ },
+ },
+ returns: {
+ schema: UPID_SCHEMA,
+ },
+ access: {
+ permission: &Permission::And(&[
+ &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_MODIFY, true),
+ &Permission::Privilege(&["system", "disks"], PRIV_SYS_MODIFY, false)
+ ]),
+ }
+)]
+/// Unmount a removable device that is associated with the datastore
+pub async fn unmount(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
+ let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
+ let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
+ do_unmount(store, auth_id, to_stdout).await
+}
+
#[api(
protected: true,
input: {
--
2.47.3
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* [pbs-devel] [PATCH proxmox-backup v3 3/4] ui: add 'unmount-on-done' field to SyncJobEdit window
2025-11-12 12:05 [pbs-devel] [PATCH proxmox{, -backup} v3 0/5] unmount datastores after sync job Hannes Laimer
` (2 preceding siblings ...)
2025-11-12 12:05 ` [pbs-devel] [PATCH proxmox-backup v3 2/4] api: datastore: auto-unmount after mount-triggered sync Hannes Laimer
@ 2025-11-12 12:05 ` Hannes Laimer
2025-11-12 12:05 ` [pbs-devel] [PATCH proxmox-backup v3 4/4] docs: add section about `unmount-on-done` Hannes Laimer
2025-11-14 22:15 ` [pbs-devel] [PATCH proxmox{, -backup} v3 0/5] unmount datastores after sync job Thomas Lamprecht
5 siblings, 0 replies; 8+ messages in thread
From: Hannes Laimer @ 2025-11-12 12:05 UTC (permalink / raw)
To: pbs-devel
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
www/window/SyncJobEdit.js | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/www/window/SyncJobEdit.js b/www/window/SyncJobEdit.js
index 14ffddcd..074c7855 100644
--- a/www/window/SyncJobEdit.js
+++ b/www/window/SyncJobEdit.js
@@ -122,6 +122,7 @@ Ext.define('PBS.window.SyncJobEdit', {
}
if (!me.isCreate) {
PBS.Utils.delete_if_default(values, 'run-on-mount', false);
+ PBS.Utils.delete_if_default(values, 'unmount-on-done', false);
PBS.Utils.delete_if_default(values, 'rate-in');
PBS.Utils.delete_if_default(values, 'rate-out');
PBS.Utils.delete_if_default(values, 'remote');
@@ -499,9 +500,34 @@ Ext.define('PBS.window.SyncJobEdit', {
'Run this job when a relevant removable datastore gets mounted.',
),
},
+ listeners: {
+ change: function (field, runOnMount) {
+ let me = this;
+ let view = me.up('pbsSyncJobEdit');
+ let unmountOnDoneCb = view.down('field[name=unmount-on-done]');
+ unmountOnDoneCb.setDisabled(!runOnMount);
+ if (!runOnMount) {
+ unmountOnDoneCb.setValue(false);
+ }
+ },
+ },
uncheckedValue: false,
value: false,
},
+ {
+ xtype: 'proxmoxcheckbox',
+ name: 'unmount-on-done',
+ fieldLabel: gettext('Unmount when done'),
+ autoEl: {
+ tag: 'div',
+ 'data-qtip': gettext(
+ 'Unmount relevant removable datastore once sync job finishes.',
+ ),
+ },
+ uncheckedValue: false,
+ value: false,
+ disabled: true,
+ },
],
},
{
--
2.47.3
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* [pbs-devel] [PATCH proxmox-backup v3 4/4] docs: add section about `unmount-on-done`
2025-11-12 12:05 [pbs-devel] [PATCH proxmox{, -backup} v3 0/5] unmount datastores after sync job Hannes Laimer
` (3 preceding siblings ...)
2025-11-12 12:05 ` [pbs-devel] [PATCH proxmox-backup v3 3/4] ui: add 'unmount-on-done' field to SyncJobEdit window Hannes Laimer
@ 2025-11-12 12:05 ` Hannes Laimer
2025-11-14 22:15 ` [pbs-devel] [PATCH proxmox{, -backup} v3 0/5] unmount datastores after sync job Thomas Lamprecht
5 siblings, 0 replies; 8+ messages in thread
From: Hannes Laimer @ 2025-11-12 12:05 UTC (permalink / raw)
To: pbs-devel
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
docs/managing-remotes.rst | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/docs/managing-remotes.rst b/docs/managing-remotes.rst
index b6ebda18..60ac3bc6 100644
--- a/docs/managing-remotes.rst
+++ b/docs/managing-remotes.rst
@@ -150,6 +150,10 @@ relevant removable datastore is mounted. If mounting a removable datastore would
multiple sync jobs, these jobs will be run sequentially in alphabetical order based on
their ID.
+If the ``unmount-on-done`` flag is set, the datastore will be automatically unmounted
+after the sync job finishes. This option is only available for sync jobs triggered by
+mounting (``run-on-mount``), enabling fully automated external drive workflows.
+
Namespace Support
^^^^^^^^^^^^^^^^^
--
2.47.3
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [pbs-devel] [PATCH proxmox{, -backup} v3 0/5] unmount datastores after sync job
2025-11-12 12:05 [pbs-devel] [PATCH proxmox{, -backup} v3 0/5] unmount datastores after sync job Hannes Laimer
` (4 preceding siblings ...)
2025-11-12 12:05 ` [pbs-devel] [PATCH proxmox-backup v3 4/4] docs: add section about `unmount-on-done` Hannes Laimer
@ 2025-11-14 22:15 ` Thomas Lamprecht
5 siblings, 0 replies; 8+ messages in thread
From: Thomas Lamprecht @ 2025-11-14 22:15 UTC (permalink / raw)
To: pbs-devel, Hannes Laimer
On Wed, 12 Nov 2025 13:05:10 +0100, Hannes Laimer wrote:
> Adds the option to automatically unmount a datastore after a sync job
> finishes.
>
> The idea is that, in combination with run-on-mount, it is possible to
> have datastores sync to external drives without the need to open the web
> ui or terminal. This came up a handful of times in support and a recent
> thread on the forum. Basically, also non-tech people could be tasked
> with plugging and unplugging different drives regularly and mounting,
> sync and unmounting would be done automatically.
>
> [...]
Applied, thanks!
[1/4] api: syncjob: correctly update/delete 'unmount-on-done' field
commit: 2eb654bac9462e67f117546f8af73d41371a55db
[2/4] api: datastore: auto-unmount after mount-triggered sync
commit: caec9e086ba37db82d8087609c8f1aaaad58a7b5
[3/4] ui: add 'unmount-on-done' field to SyncJobEdit window
commit: db024782cebe9e11e6f85781befb773b50c6fb66
[4/4] docs: add section about `unmount-on-done`
commit: 8d79779da60c8215633bbc6253afb85628a2b438
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 8+ messages in thread