jcwillox / hass-auto-backup

🗃️ Improved Backup Service for Home Assistant that can Automatically Remove Backups and Supports Generational Backup Schemes.
https://jcwillox.github.io/hass-auto-backup
MIT License
366 stars 27 forks source link

Keep Days - not work #114

Open 66krieger opened 1 year ago

66krieger commented 1 year ago

The problem

Hi, The backups made are not deleted, despite the setting. Where else can I look for the error? Sören

What version of Auto Backup has the issue?

1.4.0

What version of Home Assistant are you running?

Home Assistant 2023.7.3

What type of installation are you running?

Home Assistant Supervised

If you're running HA OS/Supervised, what version of the Supervisor are you running?

No response

Example YAML snippet

description: ab 15.02.2023
use_blueprint:
  path: jcwillox/automatic_backups.yaml
  input:
    enable_hourly: false
    enable_daily: true
    enable_weekly: true
    enable_monthly: true
    enable_yearly: false
    use_action_hourly: false
    backup_action:
      - service: auto_backup.backup_full
        data:
          keep_days: 4

/config/blueprints/automation/jcwillox/automatic_backups.yaml :

blueprint:
  name: Automatic Backups
  description: 'Create backups each day and keep them for a configurable amount of
    time, backups are stored less frequently the older they are.

    By default all backups are full backups, besides the 3-hourly backups which only
    include the configuration.

    **Template Variables:**

    - `name` — backup name configured below

    - `password` — backup password configured below

    - `keep_days` — days the backup is kept for based on the current backup type

    - `backup_type` — current schedule being created, e.g., `daily`, `weekly`, `monthly`

    **Note: requires the [Auto Backup](https://jcwillox.github.io/hass-auto-backup)
    custom integration.**

    '
  domain: automation
  input:
    backup_name:
      name: Name template used for backups
      default: "{{ backup_type | title }}Backup: {{\n  now().strftime(\n    \"%A,
        \"\n    ~ iif(backup_type == \"hourly\", \"%-I:%M %p, \", \"\")\n    ~ \"%B
        %-d, %Y\"\n  )\n}}\n{# HourlyBackup: Monday, 3:04 PM, January 2, 2006 #}\n{#
        DailyBackup: Monday, January 2, 2006 #}\n"
      selector:
        template: {}
    backup_time:
      name: Time of day to create backups
      default: 02:30:00
      selector:
        time: {}
    backup_password:
      name: Backup Password (Optional)
      default: ''
      selector:
        text:
          type: password
          multiline: false
    enable_hourly:
      name: 'Enable: Hourly Backups'
      description: Create a backup every 3 hours and store for 2 days
      default: false
      selector:
        boolean: {}
    enable_daily:
      name: 'Enable: Daily Backups'
      description: Create a backup each day and store for a week
      default: true
      selector:
        boolean: {}
    enable_weekly:
      name: 'Enable: Weekly Backups'
      description: Create a backup each week and store for a month
      default: true
      selector:
        boolean: {}
    enable_monthly:
      name: 'Enable: Monthly Backups'
      description: Create a backup each month and store for a year
      default: true
      selector:
        boolean: {}
    enable_yearly:
      name: 'Enable: Yearly Backups'
      description: Create a backup each year and store forever
      default: true
      selector:
        boolean: {}
    use_action_hourly:
      name: Use Backup Action for Hourly Backups Only
      description: Otherwise, it will be used for all backup types
      default: true
      selector:
        boolean: {}
    backup_action:
      name: Backup Action (Optional)
      description: 'Optionally override the built-in backup action with a custom action,
        designed to allow greater control over what is included in each backup.

        By default this only overrides the 3-hourly backups, so that they only include
        the configuration.

        '
      default:
      - service: auto_backup.backup
        data:
          name: '{{ name }}'
          password: '{{ password }}'
          keep_days: '{{ keep_days }}'
          include_folders:
          - config
      selector:
        action: {}
    condition:
      name: Condition (Optional)
      description: Condition to test before any action
      default: []
      selector:
        action: {}
  source_url: https://raw.githubusercontent.com/jcwillox/home-assistant-blueprints/main/automation/automatic_backups.yaml
mode: single
variables:
  password: !input backup_password
  enable_hourly: !input enable_hourly
  enable_daily: !input enable_daily
  enable_weekly: !input enable_weekly
  enable_monthly: !input enable_monthly
  enable_yearly: !input enable_yearly
  use_action_hourly: !input use_action_hourly
trigger:
- id: daily
  platform: time
  at: !input backup_time
- id: hourly
  enabled: !input enable_hourly
  platform: time_pattern
  hours: /3
condition: !input condition
action:
- if:
    condition: trigger
    id: daily
  then:
  - choose:
    - conditions:
      - '{{ enable_yearly }}'
      - '{{ now().day == 1 and now().month == 1 }}'
      sequence:
      - variables:
          backup_type: yearly
          keep_days:
      - &id001
        variables:
          name: !input backup_name
          backup_action: !input backup_action
      - &id002
        if:
        - '{{ not use_action_hourly }}'
        - '{{ backup_action | length > 0 }}'
        then: !input backup_action
        else:
        - alias: Creating a full backup (default action)
          service: auto_backup.backup
          data:
            name: '{{ name }}'
            password: '{{ password }}'
            keep_days: '{{ keep_days }}'
    - conditions:
      - '{{ enable_monthly }}'
      - '{{ now().day == 1 }}'
      sequence:
      - variables:
          backup_type: monthly
          keep_days: 365
      - *id001
      - *id002
    - conditions:
      - '{{ enable_weekly }}'
      - '{{ now().weekday() == 0 }}'
      sequence:
      - variables:
          backup_type: weekly
          keep_days: 30.4167
      - *id001
      - *id002
    - conditions:
      - '{{ enable_daily }}'
      sequence:
      - variables:
          backup_type: daily
          keep_days: 7
      - *id001
      - *id002
  else:
  - variables:
      backup_type: hourly
      keep_days: 2
  - *id001
  - if: '{{ backup_action | length > 0 }}'
    then: !input backup_action
    else:
    - alias: Creating a partial backup (default action)
      service: auto_backup.backup
      data:
        name: '{{ name }}'
        password: '{{ password }}'
        keep_days: '{{ keep_days }}'
        include_folders:
        - config

Anything in the logs that might be useful for us?

No response

Additional information

No response

hvorragend commented 1 year ago

I also use your blueprint and notice that there are always outdated backups in Supervisor. These backups (Hourly) were created by AutoBackup, but the slug name is not included in the file /config/.storage/auto_backup.snapshots_expiry. I've been observing this for a few weeks now and have absolutely no explanation for it. It is not fundamentally due to the backup type, because other hourly backups of Auto-Backup will be removed.

I see no pattern, no logic and no dependence on anything (e.g. manual deletions, backup errors).

spry-salt commented 1 year ago

Same. It seems to happen more when another service creates a backup (e.g. when you're offered to make a backup before upgrading part of HASS) and then this AutoBackup seems to lose track of backups prior to that. I often have to go and manually delete them.

tingles2233 commented 1 year ago

Same on my install. Old backups are not being removed as per the "keep_days" flag.

OneCyrus commented 11 months ago

same issue. these days almost no backups are deleted anymore. every couple of weeks i need to manually cleanup when the disk gives me a low free space warning. would be great to get this working again.

fantnhu commented 10 months ago

Same error. I create the backups with Node-Red, they succeed. I run the purge before every new save (they are set to 2 days). Unfortunately, it doesn't delete anything, it doesn't monitor anything, it just makes new ones. image image

m67hoff commented 4 months ago

Same Problem here: I use the Automation examples from: https://jcwillox.github.io/hass-auto-backup/advanced-examples/
(Full backup every day except Mondays, Full backup every Monday) to an external NAS, but purge seems not to work (already some backups deleted with find ... -mtime ...):

image
jcwillox commented 4 months ago

I can't say I've every experienced this issue, and I've been taking 3-hourly, daily, monthly backups for years now and it's never failed to track any. image So the functionality definitely works, but the question is why not for you. There are a couple options other than it being a bug.

The deletion is handled by home assistant, so if you enable info logs and see purged being called image then it's most likely out of our hands and into home assistants (or rather the supervisor), it could fail to find the backup with the slug, i.e. file was moved, or have some other file IO error. (hopefully you'd see some logs)

If you're not seeing the backup in the auto_backup.snapshots_expiry then it's not being monitored, either it didn't receive the keep_days (intentionally or misconfigured) or auto backup failed to get the id of the newly created backup, if your backups are taking over 20 minutes auto backup will timeout and not track the backup (it will still get created), all you can do is make smaller backups or increase the timeout in AB settings, but the longer the backup takes the more likely the request could timeout, meaning AB doesn't get the id. Additionally, if you restart home assistant during a backup, AB won't know when the backup is completed.