Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep x files #31

Closed
poudenes opened this issue Feb 22, 2023 · 10 comments
Closed

Keep x files #31

poudenes opened this issue Feb 22, 2023 · 10 comments

Comments

@poudenes
Copy link

poudenes commented Feb 22, 2023

Is your feature request related to a problem? Please describe.

not related to a problem

Describe the solution you'd like

Would be nice to add a extra option in jobs config:

keep_files: 3 # or what you want

I created backups with date. And want keep last 3 files.

or in this part

- name: Daily Sync Backup
  schedule: 33 10 * * *
  command: sync
  sources:
    - /backup
  destination: minio:habackup
  keep_files: 3
  config_path: /config/rclone.conf

On my VPS site I use clone also to copy backups to minio and use this command to remove files older then:

rclone delete --min-age 3d minio:habackup 

or in the config.conf file hardcoded for every job.

Describe alternatives you've considered

remove files manual from the destination location.

Additional context

No response

@poudenes
Copy link
Author

Went into the docker and created in '/root/.config/rclone' the 'rclone.conf' file also

root@19a172aa-rclone-backup:/root/.config/rclone$ rclone delete --min-age 3d minio:habackup --dry-run
2023/02/25 12:54:34 NOTICE: .samba_backup.sensor: Skipped delete as --dry-run is set (size 245)
2023/02/25 12:54:34 NOTICE: Backup-HA-2023-2-5-2023-02-22_08_30.tar: Skipped delete as --dry-run is set (size 362.383Mi)
root@19a172aa-rclone-backup:/root/.config/rclone$ 

The command rclone delete is working :). Did a --dry-run for testing.

@poudenes
Copy link
Author

Solved. Add keep_days in "hass-auto-backup" add-on.

https://github.com/jcwillox/hass-auto-backup

@jcwillox
Copy link
Owner

Yeah sorry I've been quite busy the past few weeks, but yes thats the way to go. You could also possibly use rclone delete as a scheduled job.

@poudenes
Copy link
Author

Yeah sorry I've been quite busy the past few weeks, but yes thats the way to go. You could also possibly use rclone delete as a scheduled job.

Thats an option. But still how do I add that I want keep x days?

@poudenes
Copy link
Author

poudenes commented Mar 26, 2023

It will be something like this then?

- name: Delete partial backups older then 3 days
  schedule: 0 23 * * * 
  command: delete --min-age 3d
  sources:
    - /share/backup/partial
  destination: minio:ha/partial

@jcwillox
Copy link
Owner

jcwillox commented Apr 8, 2023

Yeah that'd be the way, except you'd need to use flags/extra_flags for the arguments

- name: Delete partial backups older then 3 days
  schedule: 0 23 * * * 
  command: delete
  extra_flags:
    - "--min-age=3d"
  # you could even use include to target backups by name
  include:
      - DailyBackup*
  sources:
    - /share/backup/partial
  destination: minio:ha/partial

@Adrianni
Copy link

@jcwillox,

I'm using your suggestion in previous post:
- name: Delete partial backups older then 6 days schedule: 29 * * * * command: delete extra_flags: - "--min-age=6d" destination: JottaCloud:/Backup/Home Assistant sources: - /backup

But this gives the following error:
Command delete needs 1 arguments maximum: you provided 2 non flag arguments: ["/backup" "JottaCloud:/Backup/Home Assistant"] [2024-07-16] [13:29:00] [ERROR]: failed to run rclone command: exit status 1

If i remove the sources argument, it fails to start the addon due to the missing sources. Any suggestion how to overcome this?

@scharmach
Copy link

@Adrianni I've just installed the addon and stumbled across this issue. When I tried the code above, I got the same error.

I'll probably fine-tune this further, but this combination works for me:

- name: Alte Backups nach 14 Tagen löschen
  schedule: 0 0 * * *
  command: delete
  extra_flags:
    - "--min-age=14d"
  sources:
    - /backup
- name: Backups zu Nextcloud synchronisieren
  schedule: 30 3 * * *
  command: sync
  sources:
    - /backup
  destination: remote:/Backups/Home Assistant

Basically, I've set no destination for the delete-command.

@Adrianni
Copy link

@Adrianni I've just installed the addon and stumbled across this issue. When I tried the code above, I got the same error.

I'll probably fine-tune this further, but this combination works for me:

- name: Alte Backups nach 14 Tagen löschen
  schedule: 0 0 * * *
  command: delete
  extra_flags:
    - "--min-age=14d"
  sources:
    - /backup
- name: Backups zu Nextcloud synchronisieren
  schedule: 30 3 * * *
  command: sync
  sources:
    - /backup
  destination: remote:/Backups/Home Assistant

Basically, I've set no destination for the delete-command.

Doesn't this result in deleting files in home assistant (local source) instead of remote destination? My goal is to delete old files on destination. I've got Auto backup-integration taking care of the part deleting old files on HA (local source).

@scharmach
Copy link

@Adrianni It's deleting both:

  1. Anything older than 14 days in the Home Assistant backup-folder will be deleted.
  2. Then it does a full sync with my remote, which includes the deleted files as well as new backups.

So, this deletes the files first in Home Assistant and then via sync in my Nextcloud instance. I haven't tested it extensively in the short time I've been using it, but all test runs have been successful so far.

Auto Backup can also only delete backups that have been created by the integration itself, as far as I can tell: jcwillox/hass-auto-backup#119

That's why I came up with the solution above in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants