cupcakearmy / autorestic

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

Suggestion: Validate location after executing before hooks #332

Closed Chippit closed 3 months ago

Chippit commented 8 months ago

Currently, if you have a location with a given file path that doesn't exist at the time of executing autorestic, backups will fail, even when the file will exist after before hooks are run.

locations:
  test-location:
    from:
      - /file/does/not/yet/exist
    hooks:
      before: touch /file/does/not/yet/exist
...
stat /file/does/not/yet/exist: no such file or directory
Error: 1 errors were found

In this situation, before and after hooks do not run at all.

While it's feasible to create an empty version of this file in advance of executing autorestic, it does require the sort of manual intervention and custom scripting that autorestic otherwise resolves.

slush0 commented 7 months ago

I second this as I just wanted to report it as a bug (which it is, IMO). My use-case is that I do btrfs snapshot in before hook. Autorestic fails unless I do the first snapshot manually before the first backup, and I cannot delete the snapshot in after, otherwise it throws an error on next run.

It is not a big deal in my case, althought it took me about half an hour to realize where the problem lies, and it is a bit inconsistent with expectations of when before is executed.

hickinbottoms commented 3 months ago

I'll have a crack at creating a PR for this.

My use case is to use a hook to mount the backup source location that contains the "from" directory -- that directory doesn't exist until that mount completes, and the "before" hook runs after checking that all the "from" directories in the location exist, hence that hook is too late.