thomasmauerer / hassio-addons

My collection of addons for Home Assistant
MIT License
458 stars 54 forks source link

Feature request: add keep days to manual backups #114

Open DrBlokmeister opened 1 year ago

DrBlokmeister commented 1 year ago

I run weekly and daily backups. The weekly backups I want to keep for a longer time than the daily backups to avoid using too much disk space while still having a few weeks of history. It would be nice to add the option keep_days to the manual backup service.

Proposed config:

    - service: hassio.addon_stdin
      data:
        addon: 15d21743_samba_backup
        input:
          command: trigger
          keep_days: 30
          exclude: [a0d7b954_influxdb]
thomasmauerer commented 1 year ago

Good idea, but not trivial to implement since Samba Backup does not store any information about backups. It's not using a database or something similar to manage such information like how long to keep a certain backup file. The cleanup is entirely based on the creation date (older backups get deleted first).

ThreeFN commented 1 year ago

Could 'keep days' be implemented in the file name? It's not the prettiest solution, but that way the routine could just step through the files, compare creation date to keep days, and delete as needed? Variant on this could be using expiration timecode if one cares about it being cleaned up more regularly than 'after midnight'. If we're going crazy, you could have different local and remote expiration times, eg L{time} and R{time}. To save text space, maybe epoch/unix timestamps, possibly drop some of the least significant digit(s)?

EDIT: Or the thing I always forgets exists, hex encoding (of the unix timestamp). Or maybe base32 encoding for crazy adventures.