brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: restic unlock clears the stale lock an interrupted backup leaves behind

Backup
~/tips/tip-backup-restic-unlock

restic -r sftp:[email protected]:/restic-repo unlock

Removes the stale lock that keeps a restic repository blocked after an interrupted run.

Kill a restic backup halfway, lose the connection to your backup target or reboot during a prune, and the next run may refuse to start because the repository is locked. That sounds worse than it is. The restic docs say commands such as backup and prune can be interrupted at any point without damaging the repository, and that you might have to run unlock manually afterwards.

restic -r sftp:[email protected]:/restic-repo list locks
restic -r sftp:[email protected]:/restic-repo unlock

list locks prints the IDs of the locks in the repository, so you can see there’s something to clear. Plain unlock removes only stale locks. In restic’s design docs a lock is stale when its timestamp is older than 30 minutes, or, when it was made on the same machine, when the process that created it is gone. A lock that belongs to a backup still running somewhere else stays put.

For scheduled jobs, have a look at the global --retry-lock option too. With --retry-lock 30m a command keeps trying to lock the repository for up to half an hour instead of failing straight away, which helps when a nightly backup and a weekly prune overlap.

There’s also unlock --remove-all, which removes every lock, including ones that aren’t stale. I’d only use it when I’m sure nothing else is working on the repository, because those locks are there to keep commands like prune from running alongside others. With two servers backing up to the same repository I’d be extra careful.

Further reading: restic docs: troubleshooting, restic docs: design, locks

More Backup tips restic snapshots --group-by host,paths mysqldump --routines --events mydb > mydb.sql rsync -a --files-from=list.txt /home/me/ backup:/backup/ restic find "*.txt" restic stats All Backup tips (45) All topics

Link