# Unable to delete backups older than x days

**URL:** <https://forums.percona.com/t/unable-to-delete-backups-older-than-x-days/27201>\
**Category:** Percona Backup for MongoDB\
**Created:** [December 17, 2023, 1:43pm UTC](https://forums.percona.com/t/unable-to-delete-backups-older-than-x-days/27201 "2023-12-17T13:43:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aranjith0](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/aranjith0/32/13012_2.png) [@aranjith0](https://forums.percona.com/u/aranjith0)\
**Post date:** [December 17, 2023, 1:43pm UTC](https://forums.percona.com/t/unable-to-delete-backups-older-than-x-days/27201/1 "2023-12-17T13:43:05Z")

</div>

Team,  
we have a requirement to delete the backups which are older than 10days. I have scheduled it in cronjob, but its not happening.  
[mongod@tora-pl211 ~]$ pbm cleanup -y --older-than 10d --wait  
nothing to delete

Please let me know if any other command to replace it.

```auto
[mongod@tora-pl211 ~]$ pbm status
Cluster:
========
shard3ReplSet:
  - shard3ReplSet/pmgo-pl206.int.compumark.com:27018 [S]: pbm-agent v2.2.1 OK
  - shard3ReplSet/pmgo-pl205.int.compumark.com:27018 [P]: pbm-agent v2.2.1 OK
  - shard3ReplSet/pmgo-pl201.int.compumark.com:27028 [S]: pbm-agent v2.2.1 OK
shard1ReplSet:
  - shard1ReplSet/pmgo-pl203.int.compumark.com:27018 [S]: pbm-agent v2.2.1 OK
  - shard1ReplSet/pmgo-pl201.int.compumark.com:27018 [P]: pbm-agent v2.2.1 OK
  - shard1ReplSet/pmgo-pl202.int.compumark.com:27028 [S]: pbm-agent v2.2.1 OK
configReplSet:
  - configReplSet/pmgo-pl204.int.compumark.com:27019 [S]: pbm-agent v2.2.1 OK
  - configReplSet/pmgo-pl202.int.compumark.com:27019 [P]: pbm-agent v2.2.1 OK
  - configReplSet/pmgo-pl206.int.compumark.com:27029 [S]: pbm-agent v2.2.1 OK
shard2ReplSet:
  - shard2ReplSet/pmgo-pl204.int.compumark.com:27018 [S]: pbm-agent v2.2.1 OK
  - shard2ReplSet/pmgo-pl202.int.compumark.com:27018 [P]: pbm-agent v2.2.1 OK
  - shard2ReplSet/pmgo-pl205.int.compumark.com:27028 [S]: pbm-agent v2.2.1 OK

PITR incremental backup:
========================
Status [ON]

Currently running:
==================
(none)

Backups:
========
S3 us-east-1 s3://cm-mongo-db-shared-prod-va/percona/backup/
  Snapshots:
    2023-12-16T01:00:03Z 2.28TB <logical> [restore_to_time: 2023-12-16T12:34:09Z]
    2023-12-09T01:00:02Z 2.33TB <logical> [restore_to_time: 2023-12-09T13:10:04Z]
    2023-12-02T01:00:02Z 2.31TB <logical> [restore_to_time: 2023-12-02T13:10:25Z]
  PITR chunks [585.99GB]:
    2023-12-02T13:10:26Z - 2023-12-17T12:36:24Z

```

---

<div class="post-metadata">

**Author:** ![Agustin\_G](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/agustin_g/32/14111_2.png) [@Agustin\_G](https://forums.percona.com/u/Agustin_G)\
**Post date:** [December 18, 2023, 7:21pm UTC](https://forums.percona.com/t/unable-to-delete-backups-older-than-x-days/27201/2 "2023-12-18T19:21:35Z")

</div>

Hi Aranjith,  
What version are you using? For 2.0.5 and older, you should use a timestamp argument to the older-than flag:

```auto
For PBM version 2.0.5 and earlier, use the pbm delete backup --older-than <timestamp> command. 
You can configure a cron task to automate backup deletion by specifying the following command in the crontab file:
$ /usr/bin/pbm delete-backup -f --older-than $(date -d '-1 month' +\%Y-\%m-\%d) 
...

```

> **[Percona Backup for MongoDB - Schedule backups](https://docs.percona.com/percona-backup-mongodb/usage/schedule-backup.html#backup-storage-cleanup)**
>
> We recommend using crond or similar services to schedule backup snapshots.

---

<div class="post-metadata">

**Author:** ![aranjith0](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/aranjith0/32/13012_2.png) [@aranjith0](https://forums.percona.com/u/aranjith0)\
**Post date:** [December 19, 2023, 6:40am UTC](https://forums.percona.com/t/unable-to-delete-backups-older-than-x-days/27201/3 "2023-12-19T06:40:56Z")

</div>

> [@aranjith0](#):
>
> `v2.2.1`

Hi @Agustin_G , we use percona v2.2.1, this version has new feature to delete the backups older than x days irrespective of PITR backups.  
my question is why the command “pbm cleanup -y --older-than 10d --wait” doesn’t work in this version.

In older versions(say 2.0.x), we use “pbm delete backup --older-than ” command. but this requires to manually delete pitr first .

---

<div class="post-metadata">

**Author:** ![aranjith0](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/aranjith0/32/13012_2.png) [@aranjith0](https://forums.percona.com/u/aranjith0)\
**Post date:** [December 19, 2023, 9:20am UTC](https://forums.percona.com/t/unable-to-delete-backups-older-than-x-days/27201/4 "2023-12-19T09:20:49Z")

</div>

pbm cleanup command is not working in this version2.2.1.  
see below:

[mongod@tora-pl211 ~]$ pbm list  
Backup snapshots:  
2023-12-02T01:00:02Z [restore\_to\_time: 2023-12-02T13:10:25Z]  
2023-12-09T01:00:02Z [restore\_to\_time: 2023-12-09T13:10:04Z]  
2023-12-16T01:00:03Z [restore\_to\_time: 2023-12-16T12:34:09Z]

PITR :  
2023-12-02T13:10:26Z - 2023-12-19T00:36:14Z  
[mongod@tora-pl211 ~]$ pbm cleanup -y --older-than 10d --wait  
nothing to delete  
[mongod@tora-pl211 ~]$ pbm cleanup --older-than=“2023-12-09T01:00:00”  
nothing to delete

---

<div class="post-metadata">

**Author:** ![aranjith0](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/aranjith0/32/13012_2.png) [@aranjith0](https://forums.percona.com/u/aranjith0)\
**Post date:** [January 23, 2024, 3:04pm UTC](https://forums.percona.com/t/unable-to-delete-backups-older-than-x-days/27201/5 "2024-01-23T15:04:29Z")

</div>

Hi @percona ,  
Can someone please help, is there a alternative command to delete the backups.

[mongod@tora-pl211 ~]$ pbm cleanup -y --older-than 15d --wait  
nothing to delete  
[mongod@tora-pl211 ~]$ pbm delete-backup -f --older-than $(date -d ‘-15days’ +%Y-%m-%d);  
Waiting for delete to be done …[done]  
Backup snapshots:  
2024-01-06T01:00:02Z [restore\_to\_time: 2024-01-06T14:03:15Z]  
2024-01-13T01:00:02Z [restore\_to\_time: 2024-01-13T13:06:20Z]  
2024-01-20T01:00:02Z [restore\_to\_time: 2024-01-20T13:17:01Z]

PITR :  
2024-01-06T14:03:16Z - 2024-01-23T13:20:13Z  
Log says,  
2024-01-23T14:55:19Z I [configReplSet/pmgo-pl202.int.compumark.com:27019] [delete/2024-01-08T00:00:00Z] deleting 2024-01-06T01:00:02Z: unable to delete: backup is a base for ‘2024-01-06T14:03:15 - 2024-01-23T13:20:13’

I believe in recent version, not needed to delete pitr first.
