---
name: "borg2-with-lock"
section: "1"
platform: "linux"
package: "borgbackup2"
version: "2.0.0b19-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/borg2-with-lock"
---

# borg2-with-lock(1)

run a user specified command with the repository lock held

## NAME

borg-with-lock - run a user specified command with the repository lock held

## SYNOPSIS

borg \[common options\] with-lock \[options\] COMMAND \[ARGS...\]

## DESCRIPTION

This command runs a user-specified command while locking the repository. For example:

```
$ BORG_REPO=/mnt/borgrepo borg with-lock rsync -av /mnt/borgrepo /somewhere/else/borgrepo
```

It will first try to acquire the lock (make sure that no other operation is running in the repo), then execute the given command as a subprocess and wait for its termination, release the lock and return the user command's return code as borg's return code.

**NOTE:**

If you copy a repository with the lock held, the lock will be present in the copy. Thus, before using borg on the copy from a different host, you need to use "borg break-lock" on the copied repository, because Borg is cautious and does not automatically remove stale locks made by a different host.

## OPTIONS

See *[borg-common(1)](/borg-common/1.md)* for common options of Borg commands.

### arguments

- **COMMAND**

  command to run

- **ARGS**

  command arguments

## SEE ALSO

*[borg-common(1)](/borg-common/1.md)*

## AUTHOR

The Borg Collective
