BorgBackup (short: Borg) is a deduplicating backup program. Optionally, it supports compression and authenticated encryption.
The main goal of Borg is to provide an efficient and secure way to backup data. The data deduplication technique used makes Borg suitable for daily backups since only changes are stored. The authenticated encryption technique makes it suitable for backups to not fully trusted targets.
# Local repository, repokey encryption, BLAKE2b (often faster, since Borg 1.1)
$ borg init --encryption=repokey-blake2 /path/to/repo
# Local repository (no encryption)
$ borg init --encryption=none /path/to/repo
# Remote repository (accesses a remote borg via ssh)
# repokey: stores the (encrypted) key into <REPO_DIR>/config
$ borg init --encryption=repokey-blake2 user@hostname:backup
# Remote repository (accesses a remote borg via ssh)
# keyfile: stores the (encrypted) key into ~/.config/borg/keys/
$ borg init --encryption=keyfile user@hostname:backup
```
### `borg create`
This command creates a backup archive containing all files found while recursively traversing all paths specified. Paths are added to the archive as they are given, that means if relative paths are desired, the command has to be run from the correct directory.
| ` -n`,`--dry-run` | do not create a backup archive |
| `-s`,`--stats` | print statistics for the created archive |
| `--list` | output verbose list of items (files, dirs, …) |
| `--json` | output stats as JSON. Implies`--stats`. |
| `--stdin-nameNAME` | use NAME in archive for stdin data (default: `stdin`) |
| `--stdin-userUSER` | set user USER in archive for stdin data (default: `root`) |
| `--stdin-groupGROUP` | set group GROUP in archive for stdin data (default: `wheel`) |
| `--stdin-modeM` | set mode to M in archive for stdin data (default: 0660) |
| `--content-from-command` | interpret PATH as command and store its stdout. |
| `--paths-from-stdin` | read DELIM-separated list of paths to backup from stdin. All control is external: it will back up all files given - no more, no less. |
| `--paths-from-command` | interpret PATH as command and treat its output as`--paths-from-stdin` |
| `--paths-delimiterDELIM` | set path delimiter for`--paths-from-stdin`and`--paths-from-command`(default:`\n`) |
| `-CCOMPRESSION`,`--compressionCOMPRESSION` | select compression algorithm, see the output of the “borg help compression” command for details. |
#### Examples
```shell
# Backup ~/Documents into an archive named "my-documents"
$ borg create /path/to/repo::my-documents ~/Documents
# same, but list all files as we process them
$ borg create --list /path/to/repo::my-documents ~/Documents
# Backup ~/Documents and ~/src but exclude pyc files
$ borg create /path/to/repo::my-files \
~/Documents \
~/src \
--exclude '*.pyc'
# Backup home directories excluding image thumbnails (i.e. only
# /home/<one directory>/.thumbnails is excluded, not /home/*/*/.thumbnails etc.)
$ borg create /path/to/repo::my-files /home \
--exclude 'sh:home/*/.thumbnails'
# Backup the root filesystem into an archive named "root-YYYY-MM-DD"
# use zlib compression (good, but slow) - default is lz4 (fast, low compression ratio)
$ borg create -C zlib,6 --one-file-system /path/to/repo::root-{now:%Y-%m-%d} /
# Backup onto a remote host ("push" style) via ssh to port 2222,
# logging in as user "borg" and storing into /path/to/repo
$ borg create ssh://borg@backup.example.org:2222/path/to/repo::{fqdn}-root-{now} /
# Backup a remote host locally ("pull" style) using sshfs
$ mkdir sshfs-mount
$ sshfs root@example.com:/ sshfs-mount
$ cd sshfs-mount
$ borg create /path/to/repo::example.com-root-{now:%Y-%m-%d} .
$ cd ..
$ fusermount -u sshfs-mount
# Make a big effort in fine granular deduplication (big chunk management
# overhead, needs a lot of RAM and disk space, see formula in internals
# docs - same parameters as borg < 1.0 or attic):
$ borg create --chunker-params buzhash,10,23,16,4095 /path/to/repo::small /smallstuff
# Backup a raw device (must not be active/in use/mounted at that time)
$ borg create --read-special --chunker-params fixed,4194304 /path/to/repo::my-sdx /dev/sdX
# Backup a sparse disk image (must not be active/in use/mounted at that time)
$ borg create --sparse --chunker-params fixed,4194304 /path/to/repo::my-disk my-disk.raw
# No compression (none)
$ borg create --compression none /path/to/repo::arch ~
# Super fast, low compression (lz4, default)
$ borg create /path/to/repo::arch ~
# Less fast, higher compression (zlib, N = 0..9)
$ borg create --compression zlib,N /path/to/repo::arch ~
# Even slower, even higher compression (lzma, N = 0..9)
$ borg create --compression lzma,N /path/to/repo::arch ~
# Only compress compressible data with lzma,N (N = 0..9)
$ borg create --compression auto,lzma,N /path/to/repo::arch ~
# Use short hostname, user name and current time in archive name
$ borg create /path/to/repo::{hostname}-{user}-{now} ~
# Similar, use the same datetime format that is default as of borg 1.1
$ borg create /path/to/repo::{hostname}-{user}-{now:%Y-%m-%dT%H:%M:%S} ~
# As above, but add nanoseconds
$ borg create /path/to/repo::{hostname}-{user}-{now:%Y-%m-%dT%H:%M:%S.%f} ~
# Backing up relative paths by moving into the correct directory first
$ cd /home/user/Documents
# The root directory of the archive will be "projectA"
$ borg create /path/to/repo::daily-projectA-{now:%Y-%m-%d} projectA
```
### `borg extract`
This command extracts the contents of an archive. By default the entire archive is extracted but a subset of files and directories can be selected by passing a list of`PATHs`as arguments. The file selection can further be restricted by using the`--exclude`option.
| `--consider-checkpoints` | Show checkpoint archives in the repository contents list (default: hidden). |
| `--short` | only print file/directory names, nothing else |
| `--formatFORMAT` | specify format for file or archive listing (default for files: `{mode} {user:6} {group:6} {size:8} {mtime} {path}{extra}{NL}`; for archives: `{archive:<36} {time} [{id}]{NL}`) |
| `--json` | Only valid for listing repository contents. Format output as [JSON](../../files/JSON.md). The form of`--format`is ignored, but keys used in it are added to the [JSON](../../files/JSON.md) output. Some keys are always present. Note: [JSON](../../files/JSON.md) can only represent text. A “barchive” key is therefore not available. |
| `--json-lines` | Only valid for listing archive contents. Format output as [JSON](../../files/JSON.md) Lines. The form of`--format`is ignored, but keys used in it are added to the [JSON](../../files/JSON.md) output. Some keys are always present. Note: [JSON](../../files/JSON.md) can only represent text. A “bpath” key is therefore not available. |
| `-PPREFIX`,`--prefixPREFIX` | only consider archive names starting with this prefix. (deprecated) |
| `-aGLOB`,`--glob-archivesGLOB` | only consider archive names matching the glob. sh: rules apply (without actually using the sh: prefix), see “borg help patterns”. |
| `--sort-byKEYS` | Comma-separated list of sorting keys; valid keys are: timestamp, archive, name, id; default is: timestamp |
| `--firstN` | consider first N archives after other filters were applied |
| `--lastN` | consider last N archives after other filters were applied |
This command displays detailed information about the specified archive or repository.
Usage: `borg [common options] info [options] [REPOSITORY_OR_ARCHIVE]`
#### Options
| Option | Description |
| -------- | --------------------- |
| `--json` | format output as JSON |
### `borg mount`
This command mounts an archive as a FUSE filesystem. This can be useful for browsing an archive or restoring individual files. Unless the`--foreground`option is given the command will run in the background until the filesystem is`umounted`.
Usage: `borg [common options] mount [options] REPOSITORY_OR_ARCHIVE MOUNTPOINT [PATH...]`
| `--restrict-to-pathPATH` | restrict repository access to PATH. Can be specified multiple times to allow the client access to several directories. Access to all sub-directories is granted implicitly; PATH doesn’t need to directly point to a repository. |
| `--restrict-to-repositoryPATH` | restrict repository access. Only the repository located at PATH (no sub-directories are considered) is accessible. Can be specified multiple times to allow the client access to several repositories. Unlike`--restrict-to-path`sub-directories are not accessible; PATH needs to directly point at a repository location. PATH may be an empty directory or the last element of PATH may not exist, in which case the client may initialize a repository there. |