I am using restic version 0.12.1 on Ubuntu Server
I have a backup script that I have used for a few years now and it has been working fine until just recently I started having issues.
The script first runs unlock “restic … unlock --cleanup-cache”.
Then it runs two “restic backup …” one after the other.
Then it runs “restic forget … --compact --prune …”.
That has worked in the past but maybe some other manual operations or something has messed it up and now I get this error on the restic forget operation.
unable to create lock in backend: repository is already locked by PID 783401 on [server name] by root (UID 0, GID 0)
lock was created at 2025-07-09 06:47:34 (1m35.233288695s ago)
storage ID aaaaaaa
the `unlock` command can be used to remove stale locks
That lock must be from the restic backup command in the same script. I am trying to figure out why am I seeing this issue now and why does the restic backup command not clean up its lock?
To test it, I manually ran forget from the terminal and got the same error.
Then I ran unlock and it said “successfully removed locks”.
But then I ran forget again and it still says “repository is already locked”.
For the start stop using this ancient (from 2021) restic version and start using the latest 0.18.0
.
I may have figured out how to fix this. It was kind of confusing because it would always give the age of the lock as what I would expect from the script run its self.
I started researching what process the lock was related to and ended up taking a look at all process for restic. I found there was several processes that should not have been running. They must have been left over from some testing I was doing. So I rebooted the server and waited a few hours and was able to remove the locks.
I am not sure why there was some restic processes that had not completed but there was. It seems that if my script ends with an error even if it was not on a restic command it will leave restic process running.
I did not find a command that list all the locks but here are some that might be helpful for anyone else that lands on this page.
To find the id of what appears to be the last lock:
restic ... list locks --no-lock
To find the time and process id of the lock:
restic ... cat lock [id from last command]
Check if the process is still running (Linux\Ubuntu):
ps -p [process id from last command]
List all restic process that might be keeping a lock open (Linux\Ubuntu):
ps aux | grep restic
Have a good day.

1 Like