Your script starts with an unconditional UNlock. This is potentially dangerous because there might be some other restic instance running already whose lock you just removed forcefully.
@adamol@leftytennis@martinleben the script from adamol executes restic unlock, this removes stale locks only and is safe to use.
But if you add --remove-all then it becomes unconditional.
I could only find some good reference in the command line help:
restic unlock --help
The "unlock" command removes stale locks that have been created by other restic processes.
EXIT STATUS
===========
Exit status is 0 if the command was successful.
Exit status is 1 if there was any error.
Usage:
restic unlock [flags]
Flags:
-h, --help help for unlock
--remove-all remove all locks, even non-stale ones
When I work on Windows and OneDrive or shared network drives then sometimes restic is interrupted due to network disruptions. This leaves lock files in place. The unlock instruction at the start makes that the backup script can remove the stale lock at the next round; and if the repo is genuinly locked it will fail.
@adamol then I have some generic remarks on the script.
you source variables from the .env file. why then echo that to a --password-file option? i’d define RESTIC_PASSWORD and RESTIC_REPOSITORY in the .env and then you can remove all these --password-file and --repo lines. Refer: Backing up — restic 0.18.1 documentation
you execute three commands in the script (unlock, check, backup). In the end you only pass on one exit code from backup. However it could be that CHECK fails and BACKUP passes, in this case the exit could would be 0 (success). I’d want to be alerted for all errors. The easiest is probably to also pipe the other commands to your logfile and process the exit code in similar way as BACKUP?
you mention you want to run this before the computer shuts down. How do you do that?