|
| 1 | +--- |
| 2 | +title: Restore |
| 3 | +nav_order: 5 |
| 4 | +layout: page |
| 5 | +description: "Learn to browse and mount a Borg repository and then restore file in bulk using the `borg extract` command." |
| 6 | +--- |
| 7 | + |
| 8 | +# How to Restore Files from a Borg Backup Using the Command Line |
| 9 | + |
| 10 | +Note: You should be comfortable using the command line. If you prefer a graphical, client, look into our [Vorta Tutorial](/macos/how-to-backup-your-mac-using-the-vorta-backup-gui/) instead. These instructions should work on macOS and popular Linux flavors, like Debian, Ubuntu, as well as Red Hat, Fedora and CentOS. |
| 11 | + |
| 12 | +## Goals |
| 13 | +This article assumes that you have set up a backup workflow to a local or remote Borg repository. Now you would like to restore files from it. Borg offers two different ways to restore files. The `borg mount` command allows you to browse multiple archives and find exactly the file you are looking for. Due to some overhead from the FUSE mount library, the speed can be slower when restoring a large number of files. This is where `borg extract` comes in. If you already know which files you need, it can quickly restore large quantities of data including all metadata. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | +You should already have Borg installed and know how to use the command line. If you didn't install Borg yet, have a look at [this previous guide](https://docs.borgbase.com/linux/setup-borg-command-line/). |
| 17 | + |
| 18 | +## Step 1 - Set up FUSE |
| 19 | +The FUSE library allows mounting arbitrary file systems into user space. It's available for all popular systems. The [official Borg docs](https://borgbackup.readthedocs.io/en/stable/installation.html) have a detailed overview for each system. You will need two parts: the actual FUSE library and Python wrappers for it. |
| 20 | + |
| 21 | +**For macOS**: First install the FUSE library from Homebrew. |
| 22 | + |
| 23 | +``` |
| 24 | +$ brew cask install osxfuse |
| 25 | +``` |
| 26 | + |
| 27 | +**For Debian/Ubuntu**: The FUSE library is available from the main package repository. |
| 28 | + |
| 29 | +``` |
| 30 | +$ sudo apt-get install libfuse-dev fuse pkg-config |
| 31 | +``` |
| 32 | + |
| 33 | +**For Red Hat/CentOS**: FUSE is available from the official repository. |
| 34 | +``` |
| 35 | +$ yum install fuse-devel fuse pkgconfig |
| 36 | +``` |
| 37 | + |
| 38 | +## Step 2 - Install Python FUSE Bindings (optional) |
| 39 | +The `llfuse` [package](https://pypi.org/project/llfuse/) provides Python bindings for FUSE. If you are using the standalone binary of Borg, it already includes FUSE bindings and you can proceed to the next step. If you installed Borg from PyPi, you can install it as follows: |
| 40 | + |
| 41 | +### Install Python FUSE library |
| 42 | +Be sure to install it into the same Python environment as Borg itself. |
| 43 | + |
| 44 | +``` |
| 45 | +$ pip install llfuse |
| 46 | +``` |
| 47 | + |
| 48 | +If you installed Borg as user-package using the system Python: |
| 49 | + |
| 50 | +``` |
| 51 | +$ pip install --user llfuse |
| 52 | +``` |
| 53 | + |
| 54 | +Or you could install it together with Borg |
| 55 | + |
| 56 | +``` |
| 57 | +$ pip install borgbackup[fuse] |
| 58 | +``` |
| 59 | + |
| 60 | +## Step 3 - Validate Installation and Repository |
| 61 | +Next make sure everything is installed properly and you have access to the backup repo. |
| 62 | + |
| 63 | +``` |
| 64 | +$ borg info [email protected]:repo |
| 65 | +``` |
| 66 | + |
| 67 | +You should see output similar to this. If you get an error, be sure that you have access to the repository. If your repo is encrypted, it will also ask you for the password or keyfile. |
| 68 | + |
| 69 | +``` |
| 70 | +Repository ID: daf2e2b94a1b57f0effc96939813ef58d0af04414f92f87c3e092a99adaa90eb |
| 71 | +Location: ssh://[email protected]/./repo |
| 72 | +Encrypted: Yes (repokey BLAKE2b) |
| 73 | +Cache: /Users/manu/.cache/borg/daf2e2b94a1b57f0effc96939813ef58d0af04414f92f87c3e092a99adaa90eb |
| 74 | +Security dir: /Users/manu/.config/borg/security/daf2e2b94a1b57f0effc96939813ef58d0af04414f92f87c3e092a99adaa90eb |
| 75 | +------------------------------------------------------------------------------ |
| 76 | + Original size Compressed size Deduplicated size |
| 77 | +All archives: 665.90 MB 577.88 MB 68.41 MB |
| 78 | +
|
| 79 | + Unique chunks Total chunks |
| 80 | +Chunk index: 1359 6711 |
| 81 | +``` |
| 82 | + |
| 83 | +If you installed Borg and llfuse via PIP, you can also validate the packages are installed |
| 84 | + |
| 85 | +``` |
| 86 | +$ pip freeze | grep llfuse |
| 87 | +$ pip freeze | grep borgbackup |
| 88 | +``` |
| 89 | + |
| 90 | +Step 4 - Using `borg mount` to Browse and Restore Files |
| 91 | +The `borg mount` command allows for simple browsing and restoring individual files without their complete metadata. This is great to restore a few documents or images. |
| 92 | + |
| 93 | +First create a new folder as mount point. Since we're not working with root permissions, we won't use `/mnt`. Instead any empty folder in your home directory will suffice. |
| 94 | + |
| 95 | +``` |
| 96 | +$ mkdir borg-mnt |
| 97 | +``` |
| 98 | + |
| 99 | +Next mount the whole repository into the newly created folder. This will give us a view of *all* archives in the repository. |
| 100 | + |
| 101 | +``` |
| 102 | +$ borg mount [email protected]:repo borg-mount |
| 103 | +``` |
| 104 | + |
| 105 | +If there was no error, you should now see all your archives in the `borg-mount` folder: |
| 106 | + |
| 107 | +``` |
| 108 | +$ ls -l borg-mount |
| 109 | +``` |
| 110 | + |
| 111 | +Depending on the archive names used, the output could look like this. |
| 112 | + |
| 113 | +``` |
| 114 | +drwxr-xr-x 1 manu staff 0 Feb 16 12:04 nyx2-test-repo-2019-02-16T12:04:06 |
| 115 | +drwxr-xr-x 1 manu staff 0 Mar 5 13:12 nyx2-test-repo-2019-03-05T13:12:04 |
| 116 | +drwxr-xr-x 1 manu staff 0 Mar 19 22:36 nyx2-test-repo-2019-03-19T22:36:07 |
| 117 | +drwxr-xr-x 1 manu staff 0 Mar 25 23:29 nyx2-test-repo-2019-03-25T23:29:35 |
| 118 | +drwxr-xr-x 1 manu staff 0 Mar 26 23:02 nyx2-test-repo-2019-03-26T23:01:57 |
| 119 | +drwxr-xr-x 1 manu staff 0 Mar 27 09:21 nyx2-test-repo-2019-03-27T09:21:42 |
| 120 | +``` |
| 121 | + |
| 122 | +You can now browse this folder structure and copy the files you need. |
| 123 | + |
| 124 | +## Step 5 - Using `borg extract` to Bulk Restore Files |
| 125 | +FUSE can be slow for a large number of files and it can't restore metadata. For this reason, Borg includes a second command for fast bulk-restoring – `borg extract`. |
| 126 | + |
| 127 | +To use it, you will need to know the precise path and archive name to restore. The [`borg mount`](https://borgbackup.readthedocs.io/en/stable/usage/extract.html) command can be helpful for this. |
| 128 | + |
| 129 | +Assuming we got the archive name and path from the previous step, a possible `borg extract` command could be |
| 130 | + |
| 131 | +``` |
| 132 | +$ borg extract \ |
| 133 | + --dry-run --list \ |
| 134 | + [email protected]:repo::nyx2-test-repo-2019-02-16T12:04:06 \ |
| 135 | + /Users/manu/Documents/financial |
| 136 | +``` |
| 137 | + |
| 138 | +Due to the `--dry-run` and `--list` arguments this will print a list of files to be restored, but won't actually restore any files. To actually restore files, remove `--dry-run`. |
| 139 | + |
| 140 | +The last part of the command gives the path you're looking to restore. If you pass no paths, then *all* the data will be restored. |
| 141 | + |
| 142 | +Borg will restore your files to the current working directory. So be sure you are in the right place before running the command for real. To restore all the data from a specific snapshot to the current directory: |
| 143 | + |
| 144 | +``` |
| 145 | +$ borg extract \ |
| 146 | + --list \ |
| 147 | + [email protected]:repo::nyx2-test-repo-2019-02-16T12:04:06 |
| 148 | +``` |
| 149 | + |
| 150 | +### Conclusion |
| 151 | +Hopefully this guide gave you a good overview of possible restore options for Borg. First we looked at installing required FUSE libraries to comfortably browse a whole repository. In addition, we used the `borg extract` command to quickly restore many files including their metadata. |
| 152 | + |
| 153 | +If you're looking to complement your backup workflow with cost-effective offsite backups, also look into [BorgBase.com ](https://www.borgbase.com). There is a free tier of 5 GB for life. Paid plan start at $2/month or $.005/GB for larger plans. We also offer custom solutions to enterprise customers. This includes setting up local backup agents or evaluating your whole backup strategy. Contact [[email protected]](mailto:[email protected]) for more. |
0 commit comments