* [pbs-devel] [PATCH proxmox-backup v2] reuse-datastore: avoid creating another default prune job
@ 2024-11-25 8:59 Gabriel Goller
2024-11-25 10:10 ` Christian Ebner
0 siblings, 1 reply; 7+ messages in thread
From: Gabriel Goller @ 2024-11-25 8:59 UTC (permalink / raw)
To: pbs-devel
If a datastore with a default prune job is removed, the prune job is
preserverd as it is stored in /etc/proxmox-backup/prune.cfg. We also
create a default prune job for every datastore – this means that when
reusing a datastore that previously existed, you end up with duplicate
prune jobs.
Reported-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
v2, thanks @Christian:
- convert if-statement to inline condition
src/api2/config/datastore.rs | 41 ++++++++++++++++++++----------------
src/api2/config/prune.rs | 11 ++++++++++
2 files changed, 34 insertions(+), 18 deletions(-)
diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs
index 37d1528c70fb..cbe67cfc6ac5 100644
--- a/src/api2/config/datastore.rs
+++ b/src/api2/config/datastore.rs
@@ -23,7 +23,9 @@ use pbs_datastore::chunk_store::ChunkStore;
use crate::api2::admin::{
prune::list_prune_jobs, sync::list_config_sync_jobs, verify::list_verification_jobs,
};
-use crate::api2::config::prune::{delete_prune_job, do_create_prune_job};
+use crate::api2::config::prune::{
+ default_prune_job_existing, delete_prune_job, do_create_prune_job,
+};
use crate::api2::config::sync::delete_sync_job;
use crate::api2::config::tape_backup_job::{delete_tape_backup_job, list_tape_backup_jobs};
use crate::api2::config::verify::delete_verification_job;
@@ -150,23 +152,26 @@ pub fn create_datastore(
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
- let prune_job_config = config.prune_schedule.as_ref().map(|schedule| {
- let mut id = format!("default-{}-{}", config.name, Uuid::generate());
- id.truncate(32);
-
- PruneJobConfig {
- id,
- store: config.name.clone(),
- comment: None,
- disable: false,
- schedule: schedule.clone(),
- options: PruneJobOptions {
- keep: config.keep.clone(),
- max_depth: None,
- ns: None,
- },
- }
- });
+ let mut prune_job_config = None;
+ if !default_prune_job_existing(&config.name)? {
+ prune_job_config = config.prune_schedule.as_ref().map(|schedule| {
+ let mut id = format!("default-{}-{}", config.name, Uuid::generate());
+ id.truncate(32);
+
+ PruneJobConfig {
+ id,
+ store: config.name.clone(),
+ comment: None,
+ disable: false,
+ schedule: schedule.clone(),
+ options: PruneJobOptions {
+ keep: config.keep.clone(),
+ max_depth: None,
+ ns: None,
+ },
+ }
+ });
+ }
// clearing prune settings in the datastore config, as they are now handled by prune jobs
let config = DataStoreConfig {
diff --git a/src/api2/config/prune.rs b/src/api2/config/prune.rs
index ce7b8ce565ce..747371067225 100644
--- a/src/api2/config/prune.rs
+++ b/src/api2/config/prune.rs
@@ -77,6 +77,17 @@ pub fn do_create_prune_job(config: PruneJobConfig) -> Result<(), Error> {
Ok(())
}
+pub fn default_prune_job_existing(datastore: &str) -> Result<bool, Error> {
+ let (section_config, _digest) = prune::config()?;
+ let has_default = section_config
+ .sections
+ .keys()
+ .filter(|s| s.starts_with(&format!("default-{datastore}")))
+ .count()
+ > 0;
+ Ok(has_default)
+}
+
#[api(
protected: true,
input: {
--
2.39.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pbs-devel] [PATCH proxmox-backup v2] reuse-datastore: avoid creating another default prune job
2024-11-25 8:59 [pbs-devel] [PATCH proxmox-backup v2] reuse-datastore: avoid creating another default prune job Gabriel Goller
@ 2024-11-25 10:10 ` Christian Ebner
2024-11-25 14:37 ` Fabian Grünbichler
0 siblings, 1 reply; 7+ messages in thread
From: Christian Ebner @ 2024-11-25 10:10 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Gabriel Goller
On 11/25/24 09:59, Gabriel Goller wrote:
> If a datastore with a default prune job is removed, the prune job is
> preserverd as it is stored in /etc/proxmox-backup/prune.cfg. We also
> create a default prune job for every datastore – this means that when
> reusing a datastore that previously existed, you end up with duplicate
> prune jobs.
Looking at this once more, I am not so sure anymore that this should
only check for the default prune job? Why not check if there is any
prune job configured at all for this datastore, and only if there is
none create the new default prune job?
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pbs-devel] [PATCH proxmox-backup v2] reuse-datastore: avoid creating another default prune job
2024-11-25 10:10 ` Christian Ebner
@ 2024-11-25 14:37 ` Fabian Grünbichler
2024-11-25 16:57 ` Gabriel Goller
2024-11-25 17:10 ` Gabriel Goller
0 siblings, 2 replies; 7+ messages in thread
From: Fabian Grünbichler @ 2024-11-25 14:37 UTC (permalink / raw)
To: Gabriel Goller, Proxmox Backup Server development discussion
On November 25, 2024 11:10 am, Christian Ebner wrote:
> On 11/25/24 09:59, Gabriel Goller wrote:
>> If a datastore with a default prune job is removed, the prune job is
>> preserverd as it is stored in /etc/proxmox-backup/prune.cfg. We also
>> create a default prune job for every datastore – this means that when
>> reusing a datastore that previously existed, you end up with duplicate
>> prune jobs.
>
> Looking at this once more, I am not so sure anymore that this should
> only check for the default prune job? Why not check if there is any
> prune job configured at all for this datastore, and only if there is
> none create the new default prune job?
that would also work?
- if no prune job exists for this store, create default one
- if explicit prune job options where given, create that one
- otherwise, don't add a prune job (no options given, and one exists
already for this store)
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pbs-devel] [PATCH proxmox-backup v2] reuse-datastore: avoid creating another default prune job
2024-11-25 14:37 ` Fabian Grünbichler
@ 2024-11-25 16:57 ` Gabriel Goller
2024-11-25 17:10 ` Gabriel Goller
1 sibling, 0 replies; 7+ messages in thread
From: Gabriel Goller @ 2024-11-25 16:57 UTC (permalink / raw)
To: Fabian Grünbichler; +Cc: Proxmox Backup Server development discussion
On 25.11.2024 15:37, Fabian Grünbichler wrote:
>On November 25, 2024 11:10 am, Christian Ebner wrote:
>> On 11/25/24 09:59, Gabriel Goller wrote:
>>> If a datastore with a default prune job is removed, the prune job is
>>> preserverd as it is stored in /etc/proxmox-backup/prune.cfg. We also
>>> create a default prune job for every datastore – this means that when
>>> reusing a datastore that previously existed, you end up with duplicate
>>> prune jobs.
>>
>> Looking at this once more, I am not so sure anymore that this should
>> only check for the default prune job? Why not check if there is any
>> prune job configured at all for this datastore, and only if there is
>> none create the new default prune job?
>
>that would also work?
>
>- if no prune job exists for this store, create default one
>- if explicit prune job options where given, create that one
>- otherwise, don't add a prune job (no options given, and one exists
> already for this store)
Yep, posted a v3!
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pbs-devel] [PATCH proxmox-backup v2] reuse-datastore: avoid creating another default prune job
2024-11-25 14:37 ` Fabian Grünbichler
2024-11-25 16:57 ` Gabriel Goller
@ 2024-11-25 17:10 ` Gabriel Goller
2024-11-26 8:09 ` Fabian Grünbichler
1 sibling, 1 reply; 7+ messages in thread
From: Gabriel Goller @ 2024-11-25 17:10 UTC (permalink / raw)
To: Fabian Grünbichler; +Cc: Proxmox Backup Server development discussion
Was a bit too hasty on the previous reply.
On 25.11.2024 15:37, Fabian Grünbichler wrote:
>On November 25, 2024 11:10 am, Christian Ebner wrote:
>> On 11/25/24 09:59, Gabriel Goller wrote:
>>> If a datastore with a default prune job is removed, the prune job is
>>> preserverd as it is stored in /etc/proxmox-backup/prune.cfg. We also
>>> create a default prune job for every datastore – this means that when
>>> reusing a datastore that previously existed, you end up with duplicate
>>> prune jobs.
>>
>> Looking at this once more, I am not so sure anymore that this should
>> only check for the default prune job? Why not check if there is any
>> prune job configured at all for this datastore, and only if there is
>> none create the new default prune job?
>
>that would also work?
>
>- if no prune job exists for this store, create default one
>- if explicit prune job options where given, create that one
>- otherwise, don't add a prune job (no options given, and one exists
> already for this store)
This is the behavior that we have now?
What I intended with this patch was to ignore the default prune job
created by 'prune schedule' so that we don't create duplicated prune
jobs.
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pbs-devel] [PATCH proxmox-backup v2] reuse-datastore: avoid creating another default prune job
2024-11-25 17:10 ` Gabriel Goller
@ 2024-11-26 8:09 ` Fabian Grünbichler
2024-11-26 9:51 ` Gabriel Goller
0 siblings, 1 reply; 7+ messages in thread
From: Fabian Grünbichler @ 2024-11-26 8:09 UTC (permalink / raw)
To: Gabriel Goller; +Cc: Proxmox Backup Server development discussion
On November 25, 2024 6:10 pm, Gabriel Goller wrote:
> Was a bit too hasty on the previous reply.
>
> On 25.11.2024 15:37, Fabian Grünbichler wrote:
>>On November 25, 2024 11:10 am, Christian Ebner wrote:
>>> On 11/25/24 09:59, Gabriel Goller wrote:
>>>> If a datastore with a default prune job is removed, the prune job is
>>>> preserverd as it is stored in /etc/proxmox-backup/prune.cfg. We also
>>>> create a default prune job for every datastore – this means that when
>>>> reusing a datastore that previously existed, you end up with duplicate
>>>> prune jobs.
>>>
>>> Looking at this once more, I am not so sure anymore that this should
>>> only check for the default prune job? Why not check if there is any
>>> prune job configured at all for this datastore, and only if there is
>>> none create the new default prune job?
>>
>>that would also work?
>>
>>- if no prune job exists for this store, create default one
>>- if explicit prune job options where given, create that one
>>- otherwise, don't add a prune job (no options given, and one exists
>> already for this store)
>
> This is the behavior that we have now?
>
> What I intended with this patch was to ignore the default prune job
> created by 'prune schedule' so that we don't create duplicated prune
> jobs.
no, if a non-default prune job exists already, the default one is still
added even if just the schedule is set in the dialogue/parameters..
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pbs-devel] [PATCH proxmox-backup v2] reuse-datastore: avoid creating another default prune job
2024-11-26 8:09 ` Fabian Grünbichler
@ 2024-11-26 9:51 ` Gabriel Goller
0 siblings, 0 replies; 7+ messages in thread
From: Gabriel Goller @ 2024-11-26 9:51 UTC (permalink / raw)
To: Fabian Grünbichler; +Cc: Proxmox Backup Server development discussion
On 26.11.2024 09:09, Fabian Grünbichler wrote:
>On November 25, 2024 6:10 pm, Gabriel Goller wrote:
>> Was a bit too hasty on the previous reply.
>>
>> On 25.11.2024 15:37, Fabian Grünbichler wrote:
>>>On November 25, 2024 11:10 am, Christian Ebner wrote:
>>>> On 11/25/24 09:59, Gabriel Goller wrote:
>>>>> If a datastore with a default prune job is removed, the prune job is
>>>>> preserverd as it is stored in /etc/proxmox-backup/prune.cfg. We also
>>>>> create a default prune job for every datastore – this means that when
>>>>> reusing a datastore that previously existed, you end up with duplicate
>>>>> prune jobs.
>>>>
>>>> Looking at this once more, I am not so sure anymore that this should
>>>> only check for the default prune job? Why not check if there is any
>>>> prune job configured at all for this datastore, and only if there is
>>>> none create the new default prune job?
>>>
>>>that would also work?
>>>
>>>- if no prune job exists for this store, create default one
>>>- if explicit prune job options where given, create that one
>>>- otherwise, don't add a prune job (no options given, and one exists
>>> already for this store)
>>
>> This is the behavior that we have now?
>>
>> What I intended with this patch was to ignore the default prune job
>> created by 'prune schedule' so that we don't create duplicated prune
>> jobs.
>
>no, if a non-default prune job exists already, the default one is still
>added even if just the schedule is set in the dialogue/parameters..
Oh, got it. Will send a patch soon!
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-11-26 9:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-25 8:59 [pbs-devel] [PATCH proxmox-backup v2] reuse-datastore: avoid creating another default prune job Gabriel Goller
2024-11-25 10:10 ` Christian Ebner
2024-11-25 14:37 ` Fabian Grünbichler
2024-11-25 16:57 ` Gabriel Goller
2024-11-25 17:10 ` Gabriel Goller
2024-11-26 8:09 ` Fabian Grünbichler
2024-11-26 9:51 ` Gabriel Goller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox