2019-11-01 05:45:47 +01:00
|
|
|
---
|
|
|
|
title: How to extract a backup
|
2020-08-21 23:27:47 +02:00
|
|
|
eleventyNavigation:
|
2022-05-20 20:11:35 +02:00
|
|
|
key: 📤 Extract a backup
|
2020-08-21 23:27:47 +02:00
|
|
|
parent: How-to guides
|
2022-06-17 00:30:53 +02:00
|
|
|
order: 7
|
2019-11-01 05:45:47 +01:00
|
|
|
---
|
|
|
|
## Extract
|
|
|
|
|
|
|
|
When the worst happens—or you want to test your backups—the first step is
|
|
|
|
to figure out which archive to extract. A good way to do that is to use the
|
2022-08-16 00:04:40 +02:00
|
|
|
`rlist` action:
|
2019-11-01 05:45:47 +01:00
|
|
|
|
|
|
|
```bash
|
2022-08-16 00:04:40 +02:00
|
|
|
borgmatic rlist
|
2019-11-01 05:45:47 +01:00
|
|
|
```
|
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
(No borgmatic `rlist` action? Try `list` instead or upgrade borgmatic!)
|
2019-11-01 05:45:47 +01:00
|
|
|
|
|
|
|
That should yield output looking something like:
|
|
|
|
|
|
|
|
```text
|
2023-03-07 07:41:43 +01:00
|
|
|
host-2023-01-01T04:05:06.070809 Tue, 2023-01-01 04:05:06 [...]
|
|
|
|
host-2023-01-02T04:06:07.080910 Wed, 2023-01-02 04:06:07 [...]
|
2019-11-01 05:45:47 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Assuming that you want to extract the archive with the most up-to-date files
|
|
|
|
and therefore the latest timestamp, run a command like:
|
|
|
|
|
|
|
|
```bash
|
2023-03-07 07:41:43 +01:00
|
|
|
borgmatic extract --archive host-2023-01-02T04:06:07.080910
|
2019-11-01 05:45:47 +01:00
|
|
|
```
|
|
|
|
|
2022-08-18 19:19:11 +02:00
|
|
|
(No borgmatic `extract` action? Upgrade borgmatic!)
|
2019-11-01 05:45:47 +01:00
|
|
|
|
2022-08-18 19:19:11 +02:00
|
|
|
Or simplify this to:
|
2020-01-30 02:08:03 +01:00
|
|
|
|
|
|
|
```bash
|
|
|
|
borgmatic extract --archive latest
|
|
|
|
```
|
|
|
|
|
2019-11-01 05:45:47 +01:00
|
|
|
The `--archive` value is the name of the archive to extract. This extracts the
|
|
|
|
entire contents of the archive to the current directory, so make sure you're
|
2022-08-18 19:19:11 +02:00
|
|
|
in the right place before running the command—or see below about the
|
|
|
|
`--destination` flag.
|
2019-11-01 05:45:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
## Repository selection
|
|
|
|
|
|
|
|
If you have a single repository in your borgmatic configuration file(s), no
|
|
|
|
problem: the `extract` action figures out which repository to use.
|
|
|
|
|
|
|
|
But if you have multiple repositories configured, then you'll need to specify
|
2023-03-27 18:46:39 +02:00
|
|
|
the repository to use via the `--repository` flag. This can be done either
|
|
|
|
with the repository's path or its label as configured in your borgmatic configuration file.
|
2019-11-01 05:45:47 +01:00
|
|
|
|
|
|
|
```bash
|
2023-03-07 07:41:43 +01:00
|
|
|
borgmatic extract --repository repo.borg --archive host-2023-...
|
2019-11-01 05:45:47 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
## Extract particular files
|
|
|
|
|
|
|
|
Sometimes, you want to extract a single deleted file, rather than extracting
|
2019-11-01 18:00:26 +01:00
|
|
|
everything from an archive. To do that, tack on one or more `--path` values.
|
|
|
|
For instance:
|
2019-11-01 05:45:47 +01:00
|
|
|
|
|
|
|
```bash
|
2023-07-14 04:25:14 +02:00
|
|
|
borgmatic extract --archive latest --path path/1 --path path/2
|
2019-11-01 05:45:47 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Note that the specified restore paths should not have a leading slash. Like a
|
2022-08-18 19:19:11 +02:00
|
|
|
whole-archive extract, this also extracts into the current directory by
|
|
|
|
default. So for example, if you happen to be in the directory `/var` and you
|
|
|
|
run the `extract` command above, borgmatic will extract `/var/path/1` and
|
|
|
|
`/var/path/2`.
|
|
|
|
|
2019-11-01 05:45:47 +01:00
|
|
|
|
2023-03-07 07:59:34 +01:00
|
|
|
### Searching for files
|
|
|
|
|
|
|
|
If you're not sure which archive contains the files you're looking for, you
|
|
|
|
can [search across
|
|
|
|
archives](https://torsion.org/borgmatic/docs/how-to/inspect-your-backups/#searching-for-a-file).
|
|
|
|
|
|
|
|
|
2019-11-01 18:00:26 +01:00
|
|
|
## Extract to a particular destination
|
|
|
|
|
|
|
|
By default, borgmatic extracts files into the current directory. To instead
|
|
|
|
extract files to a particular destination directory, use the `--destination`
|
|
|
|
flag:
|
|
|
|
|
|
|
|
```bash
|
2022-08-18 19:19:11 +02:00
|
|
|
borgmatic extract --archive latest --destination /tmp
|
2019-11-01 18:00:26 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
When using the `--destination` flag, be careful not to overwrite your system's
|
|
|
|
files with extracted files unless that is your intent.
|
|
|
|
|
2019-11-01 05:45:47 +01:00
|
|
|
|
|
|
|
## Database restoration
|
|
|
|
|
|
|
|
The `borgmatic extract` command only extracts files. To restore a database,
|
|
|
|
please see the [documentation on database backups and
|
|
|
|
restores](https://torsion.org/borgmatic/docs/how-to/backup-your-databases/).
|
|
|
|
borgmatic does not perform database restoration as part of `borgmatic extract`
|
|
|
|
so that you can extract files from your archive without impacting your live
|
|
|
|
databases.
|
|
|
|
|
|
|
|
|
2019-11-25 23:56:20 +01:00
|
|
|
## Mount a filesystem
|
|
|
|
|
|
|
|
If instead of extracting files, you'd like to explore the files from an
|
|
|
|
archive as a [FUSE](https://en.wikipedia.org/wiki/Filesystem_in_Userspace)
|
|
|
|
filesystem, you can use the `borgmatic mount` action. Here's an example:
|
|
|
|
|
|
|
|
```bash
|
2022-08-18 19:19:11 +02:00
|
|
|
borgmatic mount --archive latest --mount-point /mnt
|
2019-11-25 23:56:20 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
This mounts the entire archive on the given mount point `/mnt`, so that you
|
|
|
|
can look in there for your files.
|
|
|
|
|
2019-12-07 00:58:54 +01:00
|
|
|
Omit the `--archive` flag to mount all archives (lazy-loaded):
|
|
|
|
|
|
|
|
```bash
|
|
|
|
borgmatic mount --mount-point /mnt
|
|
|
|
```
|
|
|
|
|
2022-06-03 05:35:39 +02:00
|
|
|
Or use the "latest" value for the archive to mount the latest archive:
|
2020-01-30 02:08:03 +01:00
|
|
|
|
|
|
|
```bash
|
|
|
|
borgmatic mount --archive latest --mount-point /mnt
|
|
|
|
```
|
|
|
|
|
2019-11-25 23:56:20 +01:00
|
|
|
If you'd like to restrict the mounted filesystem to only particular paths from
|
|
|
|
your archive, use the `--path` flag, similar to the `extract` action above.
|
|
|
|
For instance:
|
|
|
|
|
|
|
|
```bash
|
2022-08-18 19:19:11 +02:00
|
|
|
borgmatic mount --archive latest --mount-point /mnt --path var/lib
|
2019-11-25 23:56:20 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
When you're all done exploring your files, unmount your mount point. No
|
|
|
|
`--archive` flag is needed:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
borgmatic umount --mount-point /mnt
|
|
|
|
```
|