autorestic icon indicating copy to clipboard operation
autorestic copied to clipboard

Suggestion: Validate location after executing before hooks

Open Chippit opened this issue 2 years ago • 1 comments

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.

Chippit avatar Oct 18 '23 08:10 Chippit

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.

slush0 avatar Nov 20 '23 19:11 slush0

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.

hickinbottoms avatar Mar 09 '24 16:03 hickinbottoms