2

I am trying to run the "check" function of backup program "restic" on one of the backup repositories it's created. No matter what I do, it crashes due to a fatal "already locked" problem. Here is the relevant command-line I/O:

tomc@ANB:~/programs/restic-backup$ ./restic check -r
/media/tomc/usbhd4-p2/_restic-bkup/dropbox using temporary cache in /tmp/restic-check-cache-405001323 
enter password for repository:
repository fd5c0b03 opened successfully, password is correct 
created new cache in /tmp/restic-check-cache-405001323 
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 (509h0m19.239359465s ago) storage ID 0fe63838 

What can I do to resolve this?

2
repository is already locked by PID 30546 on ANB by tomc

You should first use ps -fp 30546 to see if the process that locked the repository still exists. Since the lock is already 509h old according to the error message, the process might be hung, or it might be a stale lockfile if the process does not exist or seems completely unrelated.

If the process with PID 30546 seems related, you might use lsof -p 30546 to see which files it has open. With luck, one of those files might be a log file that might provide more information about the state of the process. If it seems safe to interrupt, you could use kill 30546 to try and stop it relatively nicely, allowing it a chance to clean up its lock file as it exits.

If the process refuses to die with the kill 30546 command, you could use kill -9 30546 to force it to stop, but in that case, you will definitely have to take further steps to clear the lock.

According to issue #1450 in the GitHub page of restic, after killing the hung process, you might use this command to clear the stale lock:

./restic unlock -r /media/tomc/usbhd4-p2/_restic-bkup/dropbox 

If the hung process was in the middle of some backup operation, you might need to perform these commands too:

./restic check -r /media/tomc/usbhd4-p2/_restic-bkup/dropbox 

# if the check returns "not referenced in any index" errors, then do this:
./restic rebuild-index -r /media/tomc/usbhd4-p2/_restic-bkup/dropbox 
./restic check -r /media/tomc/usbhd4-p2/_restic-bkup/dropbox 

# if there is still "not referenced in any index" errors, remove incomplete packs:
./restic prune -r /media/tomc/usbhd4-p2/_restic-bkup/dropbox 
./restic check -r /media/tomc/usbhd4-p2/_restic-bkup/dropbox 

After this, the check should pass without errors.

  • A variant worked: ./restic unlock --remove-all -r /media/tomc/usbhd4-p2/_restic-bkup/dropbox The --remove-all flag was needed because the lock happened as a result of my killing a previous restic process, and thus was not a mere "stale lock". Thanks you for your exceptionally clear and detailed response. It far exceeded my expectations. – Tom Cloyd Oct 30 '19 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.