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

Hooks to have access to location path #340

Open
JokerQyou opened this issue Nov 30, 2023 · 1 comment
Open

Hooks to have access to location path #340

JokerQyou opened this issue Nov 30, 2023 · 1 comment

Comments

@JokerQyou
Copy link

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
Copy link

r3nor commented May 8, 2024

This would be great!

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

2 participants