cupcakearmy / autorestic

Config driven, easy backup cli for restic.
https://autorestic.vercel.app/
Apache License 2.0
1.27k stars 71 forks source link

Hooks to have access to location path #340

Open JokerQyou opened 10 months ago

JokerQyou commented 10 months ago

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

Yes. For some docker compose project I'd like to backup some host-bind data directories. They are not docker volumes, just files in the same directory as docker-compose.yml file. Before running the backup, the containers must be stopped (to prevent them from writing to the files being backed up), so the before hook is a good place to handle this logic. But after reading and testing, it turns out autorestic does not expose the path of backup location to hooks, we can only get the location name, which is not very helpful in this case.

For example, a simple docker compose project is at /opt/myproject:

/opt/myproject
  |- docker-compose.yml
  |- .env
  |- data/
      |- xxx

And here's config file for autorestic:

version: 2
backends:
  test:
    type: local
    path: /tmp/test-backup
    key: lVIasxxxxxx
locations:
  myproject:
    from: /opt/myproject
    to:
      - test
    hooks:
      before:
        - cd ${AUTORESTIC_LOCATION_PATH} && docker compose stop
      after:
        - cd ${AUTORESTIC_LOCATION_PATH} && docker compose start

A possible workaround would be to use cd /opt/${AUTORESTIC_LOCATION_NAME} && docker compose stop as the before hook. But I've got different base directories for many docker compose projects, I'd like to reuse the hooks definition with YAML anchors, so it would not need to be repeated.

Describe the solution you'd like

It would be helpful to expose AUTORESTIC_LOCATION_PATH environment variable to hooks (all the hooks).

r3nor commented 4 months ago

This would be great!