Cannot "check" repository because "is already locked"

Relevant command line I/O:

tomc@ANB:~/programs/restic-backup$ sudo ./restic check -r /media/tomc/usbhd4-p2/_restic-bkup/dropbox
[sudo] password for tomc:
using temporary cache in /tmp/restic-check-cache-294690112
enter password for repository:
repository fd5c0b03 opened successfully, password is correct
created new cache in /tmp/restic-check-cache-294690112
create exclusive lock for repository
Fatal: unable to create lock in backend: repository is already locked by PID 30546 on ANB by tomc (UID 1000, GID 1000)
lock was created at 2019-10-07 14:49:41 (505h51m58.756012831s ago)
storage ID 0fe63838
tomc@ANB:~/programs/restic-backup$

I’m a psychotherapist, so my grasp of what I’m doing is limited!

I don’t understand quite what the problem is and have NO idea how to fix it.

I’ll be grateful for any help offered.

Looks like a lock from long time ago. You can use unlock option
restic -r repo unlock

1 Like

Yup, restic unlock will definitely do the trick.

1 Like

Oddly, the problem remains. Relevant command line I/O:

tomc@ANB:~/programs/restic-backup$ ./restic unlock -r /media/tomc/usbhd4-p2/_restic-bkup/dropbox
enter password for repository:
repository fd5c0b03 opened successfully, password is correct
successfully removed locks
tomc@ANB:~/programs/restic-backup$ sudo ./restic forget --prune --keep-monthly 1 --keep-weekly 3 --keep-daily 6 -r /media/tomc/usbhd4-p2/_restic-bkup/dropbox
enter password for repository:
repository fd5c0b03 opened successfully, password is correct
Fatal: unable to create lock in backend: repository is already locked exclusively by PID 11638 on ANB by tomc (UID 1000, GID 1000)
lock was created at 2019-10-29 21:00:58 (1m40.627107597s ago)
storage ID 8245cefd
tomc@ANB:~/programs/restic-backup$

The lock timestamp is due to having manually terminated a check operation due “permission denied” errors - I needed to run as root but didn’t. I retried as root, only to encounter “already locked” error. Then I did what you see above, with the result you see.

UPDATE: The repository named above is not even accessible for the normal backup run I do this time of night. I’m just unable to access it, even though the unlock operation indicates success.

tomc@ANB:~/programs/restic-backup$ ./restic unlock -r /media/tomc/usbhd4-p2/_restic-bkup/dropbox
enter password for repository:
repository fd5c0b03 opened successfully, password is correct
successfully removed locks
tomc@ANB:~/programs/restic-backup$ sh restic-backup-scripts/bk-drop
||||||||||||||||||||||||||||||||||||||||||||||||
Tue Oct 29 21:23:01 PDT 2019
=== restic backup of /dropbox - ver. 2 ===
[sudo] password for tomc:
repository fd5c0b03 opened successfully, password is correct
Fatal: unable to create lock in backend: repository is already locked exclusively by PID 11638 on ANB by tomc (UID 1000, GID 1000)
lock was created at 2019-10-29 21:00:58 (22m14.346534694s ago)
storage ID 8245cefd
=== END restic backup of /dropbox ===
tomc@ANB:~/programs/restic-backup$

Any ideas on why this is happening, and what I can do about it?

restic check acquires an exclusive lock because it cannot function if the repository is concurrently modified in any way, including the addition of new data. If you forcefully terminated this operation (SIGKILL) then it wouldn’t’ve had the chance to clean up its lock. This is why the backup cannot run.

restic unlock only removes stale locks by default. This lock was not old enough to be stale:

If you are absolutely positive that there are no outstanding processes holding locks on the repository, you can remove all locks with restic unlock --remove-all.

1 Like

That did it!

Thank you for the speedy response. Finding restic, and this excellent forum, has been so helpful for me!

1 Like

I also have this error when running restic check.
If I do manual restic unlock and restic check all is fine

My backup runs daily at 21:00 until ~21:15
Today there is error “lock was created at 2019-11-04 21:15”
Yesterday it was error “lock was created at 2019-11-03 21:14”

So each day something does not remove the lock which causes problem the next day.
The PIDs that are mentioned here are of course no longer running processes.

the script only does: unmount, backup, check, mount

Any ideas?