resticprofile icon indicating copy to clipboard operation
resticprofile copied to clipboard

Forward restic exit code from resticprofile

Open arberg opened this issue 1 year ago • 5 comments

Please, pretty please, forward restic exit code from resticprofile.

I would like to be able to do automation based on exit code from restic. If restic is never called, of cause do as you decide. But if restic is invoked I can do error-handling based on the actual code, possibly choosing between different retry strategies.

Tested on 0.28.1.

PS C:\ToolsAdmin\Restic> .\resticprofile.exe bnrgit-frequent-to-tower-ssd.forget
2024/10/05 22:20:56 using configuration file: profiles.yaml
2024/10/05 22:20:56 assuming restic is at latest known version ; exec: "restic.exe": cannot run executable found relative to current directory
2024/10/05 22:20:56 Failed parsing profile section "tag": '' expected a map, got 'slice'
2024/10/05 22:20:56 profile 'bnrgit-frequent-to-tower-ssd': starting 'forget'
repository 3ed62ea6 opened (version 2, compression level max)
repo already locked, waiting up to 0s for the lock
unable to create lock in backend: repository is already locked by PID 17900 on Muaddib by MUADDIB\Administrator (UID 0, GID 0)
lock was created at 2024-10-05 22:20:45 (10.7065338s ago)
storage ID 1303b763
the `unlock` command can be used to remove stale locks
2024/10/05 22:20:56 forget on profile 'bnrgit-frequent-to-tower-ssd': exit status 11
PS C:\ToolsAdmin\Restic> $LASTEXITCODE
1
PS C:\ToolsAdmin\Restic> .\restic.exe forget
repository 3ed62ea6 opened (version 2, compression level auto)
repo already locked, waiting up to 0s for the lock
unable to create lock in backend: repository is already locked by PID 17900 on Muaddib by MUADDIB\Administrator (UID 0, GID 0)
lock was created at 2024-10-05 22:20:45 (16.7413853s ago)
storage ID 1303b763
the `unlock` command can be used to remove stale locks
PS C:\ToolsAdmin\Restic> $LASTEXITCODE
11
PS C:\ToolsAdmin\Restic>

arberg avatar Oct 05 '24 20:10 arberg

Also if you happen to know why I get this line, i would appreciate it. I guess its something with my setup. restic.exe is in the current dir, its not on the path, so it should be executed as ./restic.exe.

Possibly its a bug i resticprofile if it use different restic invocation for checking version than for actually executing the task.

2024/10/05 22:20:56 assuming restic is at latest known version ; exec: "restic.exe": cannot run executable found relative to current directory

arberg avatar Oct 05 '24 20:10 arberg

Please, pretty please, forward restic exit code from resticprofile.

I would like to be able to do automation based on exit code from restic. If restic is never called, of cause do as you decide. But if restic is invoked I can do error-handling based on the actual code, possibly choosing between different retry strategies.

restic returning different error codes is a new feature actually, resticprofile hasn't caught up yet. I was planning on returning restic codes 👍🏻

About your example using locks, resticprofile can already try to unlock the repository automatically for you, documentation here: https://creativeprojects.github.io/resticprofile/usage/locks/index.html

creativeprojects avatar Oct 05 '24 20:10 creativeprojects

2024/10/05 22:20:56 assuming restic is at latest known version ; exec: "restic.exe": cannot run executable found relative to current directory

I haven't seen this error before, although I'm no longer using a Windows machine. Does the restic.exe have some weird permissions?

You can try to specify the location of the restic.exe in the global section if that helps

creativeprojects avatar Oct 05 '24 20:10 creativeprojects

In a PowerShell console, at least, Windows does not execute from the current working directory unless explicitly told to do so with .\some-command.exe.

Windows Terminal defaults to PowerShell unless you have overridden that, and on Windows 11 the right-click on the Start Menu popup defaults to using Windows Terminal.

This may be your issue.

danielfdickinson avatar Oct 06 '24 00:10 danielfdickinson

Thank you both.

Cool to hear its a new restic feature, no wonder you were not forwarding the exit code yet.

Fred, regarding locks thank you, I know about it and appreciate that feature greatly. But thank you for the heads up. In this case the other program was running and I was considering adding some error-code handling to my scripts.

Btw. I've created powershell wrappers around restic-profile. The powershell scripts are crossplatform so can be used for both windows and linux, and I use it for both, though mostly I think its useful for the task-handling of the windows backups. Hopefully I'll publish it soon.

Thank you Daniel, it helped setting the path env, or setting the mentioned restic-binary to full path, that made the warning go away. Indeed in my case, restic was not on the path and I'm using powershell and therefore one had to run ./restic. But it worked for backup, as in resticprofile could find restic and launch the backup, so I was confused about the waning/error.

You can close this, if you don't think there's anything else to add or consider about the warning.

arberg avatar Oct 06 '24 20:10 arberg