Borg is an excellent backup software. One of its features allows you to mount your backups and access all files in them. This is done by informing borg mount the repository and the archive you want to mount.

However, in many cases, you don’t know which archive you need until you see a list of what is available. So my workflow for mounting a Borg archive is typically this:

  • Determine which repository contains the archive.
  • cd into it.
  • Issue borg list . to show me the archives on that repository.
  • Pick one of those archives.
  • Pick an empty directory for the mounting.
  • Tell Borg my passphrase.
  • Mount the archive with borg .::${archive_name} ${mount_path} (this is the most tedious part since we need to type the full archive name and the mount path).
  • cd to the mount point or open my file manager and browse to it.
  • After I’m done, remember to type the appropriate command to umount the archive.

It’s easy to see how having to repeatedly issue those commands can become tedious and frustrating (not to mention error prone).

So I wrote a simple Bash script to automate this task.

It works like this: the script lists all your Borg repositories and archives. You just need to select which one you want, by typing a number. Then, the archive is mounted for you and your file manager pops up with it (if you are using a graphical interface).

You also don’t need to type your passphrase, since the script also automatically sources it, if you configure BORG_PASSCOMMAND or BORG_PASSPHRASE.

After you are done, you can just press enter and the archive will be umounted.

So from all that huge list of commands, we came to just type this:

$ borg-mount
2  # the repo number
8  # the archive number
↵  # umount when done

Cool, uh?

You can find the script here.

To use it, change the two constants at the top to reflect your paths. Then, chmod +x borg-mount and run it.

The script runs without arguments. Optionally, you can pass it a path that will override REPOS_DIR. If you do this, BORG_PASSCOMMAND also won’t be set. This option is handy if, at some point, you need to deal with repos placed on a different path and don’t want to mess with the constants.

You also probably want to do some adapting to your use case, so feel free.