resticprofile icon indicating copy to clipboard operation
resticprofile copied to clipboard

Tags on schedules

Open d11ahirst opened this issue 1 year ago • 4 comments

Hi

This is more a question.

I have been looking at the documentation to see if there is a way of setting the tags based on the scheduled frequency of the backup i.e hourly or weekly etc.

Is this possible?

Thanks

d11ahirst avatar May 24 '23 13:05 d11ahirst

At the moment it not possible using a scripted or template approach since we don't have:

  • Any environment variables set that would tell the profile run is scheduled (and with what settings)
  • A way to dynamically set the environment from a shell hook (e.g. to set tags based on some evaluation done in the shell script)

What is possible is using inheritance (example uses version=2 to have support for __APPEND):

version = "2"

[profiles.default]
  initialize = true
  repository = "{{ .Env.RESTIC_REPOSITORY }}"

  [profiles.default.backup]
    exclude = [ "~*", ".*" ]
    tag = [ "root" ]
    source = [ "/foldertobackup" ]
    schedule-permission = "system"
    schedule-priority = "background"
    schedule-lock-wait = "10m"
    schedule-log = "backup.log"

[profiles.hourly]
  inherit = "default"
  
  [profiles.hourly.backup]
  tag__APPEND = ["hourly"]
  schedule = "hourly"

[profiles.daily]
  inherit = "default"
  
  [profiles.daily.backup]
  tag__APPEND = ["daily"]
  schedule = "daily"
➜ resticprofile hourly.show
...
profile hourly:
    backup:
        tag:      root
                  hourly
        source:   /foldertobackup
        exclude:  ~*
                  .*

schedule hourly-backup:
    profiles:    hourly
    run:         backup
    schedule:    hourly
    permission:  system
    log:         backup.log
    priority:    background
    lock-wait:   10m0s
➜ resticprofile show       
...
profile default:
    backup:
        tag:      root
        source:   /foldertobackup
        exclude:  ~*
                  .*

jkellerer avatar May 24 '23 15:05 jkellerer

Thanks for the explanation, It would be good if I could do via script hooks of even add tags automatically using version 1 script hooks.

The problem I am trying to achieve is within a web UI to automatically display what kind of scheduled backup it was.

Thanks

clumbo avatar May 29 '23 16:05 clumbo

Hi

There is a problem with the v2 solution if I have the following schedule

[profiles.default.retention]
    before-backup = false
    after-backup = true
    keep-hourly = 24
    keep-daily = 6
    keep-weekly = 4
    keep-tag = [ "manual" ]
    prune = false

then everything is getting tagged as root,hourly. daily is missing

Any solution for this?

Thanks

d11ahirst avatar Jun 05 '23 10:06 d11ahirst

@clumbo: What we could offer is an env variable with scheduling details (comparable to the user-agent header in HTTP protocol). That would allow to set tags using templates.

@d11ahirst: do you mean you had used the example above (with inheritance) and your daily schedule produces snapshots without daily tag? Could you share more details on your config?

Also it could be that retention selects all the daily snapshots. Try adding "tag = true" to retention. We should have different defaults here tags are not used by default when tag is not set here.

jkellerer avatar Jun 05 '23 11:06 jkellerer