Skip to content

Commit eb82eeb

Browse files
Merge pull request #9369 from mr-raj12/docs-platformdirs-7332
docs: document platformdirs change and platform-specific directory paths, fixes #7332
2 parents 7be6fcd + 02f4475 commit eb82eeb

File tree

8 files changed

+145
-20
lines changed

8 files changed

+145
-20
lines changed

docs/changes.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,19 @@ Compatibility notes:
126126

127127
- XDG_*_HOME is not honoured on macOS and on Windows.
128128
- BORG_BASE_DIR can still be used to enforce some base dir + .config/ or .cache/.
129-
- the default macOS config and cache dir will now be in ~/Library/Application Support/borg/.
129+
- on macOS, the default directories move to native locations:
130+
config/data: ``~/Library/Application Support/borg/``,
131+
cache: ``~/Library/Caches/borg/``,
132+
runtime: ``~/Library/Caches/TemporaryItems/borg/``.
133+
- on Windows, the default directories are:
134+
config: ``C:\Users\<user>\AppData\Roaming\borg``,
135+
cache: ``C:\Users\<user>\AppData\Local\borg\Cache``,
136+
data: ``C:\Users\<user>\AppData\Local\borg``.
137+
- **keyfile users on macOS (and Windows)**: borg 2 will look for key files in the
138+
new platform-specific config directory instead of ``~/.config/borg/keys/`` where
139+
borg 1.x stored them. You can set ``BORG_KEYS_DIR`` to point to the old location,
140+
or copy the key file to the new location. See :ref:`env_vars` and the ``borg transfer``
141+
documentation for details.
130142
- create: different included/excluded status chars, #7321
131143

132144
- dry-run: now uses "+" (was: "-") and "-" (was: "x") for included/excluded status

docs/faq.rst

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,21 @@ Security
375375

376376
.. _home_config_borg:
377377

378-
How important is the $HOME/.config/borg directory?
379-
--------------------------------------------------
378+
How important is the borg config directory?
379+
-------------------------------------------
380380

381-
The Borg config directory has content that you should take care of:
381+
The borg config directory (``~/.config/borg`` on Linux,
382+
``~/Library/Application Support/borg`` on macOS,
383+
``C:\Users\<user>\AppData\Roaming\borg`` on Windows -- see :ref:`env_vars`)
384+
has content that you should take care of:
382385

383386
``keys`` subdirectory
384387
All your borg keyfile keys are stored in this directory. Please note that borg
385388
repokey keys are stored inside the repository. In any case, you MUST make sure
386389
to have an independent backup of the borg keys, see :ref:`borg_key_export` for
387390
more details.
388391

389-
Make sure that only you have access to the Borg config directory.
392+
Make sure that only you have access to the borg config directory.
390393

391394

392395
Note about creating multiple keyfile repositories at the same path
@@ -398,7 +401,7 @@ was moved away or unmounted), Borg will not overwrite or reuse the existing
398401
key file in your keys directory. Instead, it creates a new key file by
399402
appending a numeric suffix to the base name (e.g., .2, .3, ...).
400403

401-
This means you may see multiple key files like:
404+
This means you may see multiple key files like (example paths for Linux):
402405

403406
- ~/.config/borg/keys/home_user_backup
404407
- ~/.config/borg/keys/home_user_backup.2
@@ -410,10 +413,13 @@ overwrite.
410413

411414
.. _home_data_borg:
412415

413-
How important is the $HOME/.local/share/borg directory?
414-
-------------------------------------------------------
416+
How important is the borg data directory?
417+
-----------------------------------------
415418

416-
The Borg data directory has content that you should take care of:
419+
The borg data directory (``~/.local/share/borg`` on Linux,
420+
``~/Library/Application Support/borg`` on macOS,
421+
``C:\Users\<user>\AppData\Local\borg`` on Windows -- see :ref:`env_vars`)
422+
has content that you should take care of:
417423

418424
``security`` subdirectory
419425
Each directory here represents one Borg repository by its ID and contains the last known status.

docs/internals/data-structures.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,8 @@ Key files
736736
.. seealso:: The :ref:`key_encryption` section for an in-depth review of the key encryption.
737737

738738
When initializing a repository with one of the "keyfile" encryption modes,
739-
Borg creates an associated key file in ``$HOME/.config/borg/keys``.
739+
Borg creates an associated key file in the keys subdirectory of the borg config
740+
directory (see :ref:`env_vars` for platform-specific default paths).
740741

741742
The same key is also used in the "repokey" modes, which store it in the repository.
742743

docs/usage/general/environment.rst.inc

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,30 +161,86 @@ Some automatic "answerers" (if set, they automatically answer confirmation quest
161161
.. _XDG env var: https://specifications.freedesktop.org/basedir-spec/0.6/ar01s03.html
162162

163163
Directories and files:
164+
165+
.. note::
166+
167+
Borg 2 uses the `platformdirs <https://pypi.org/project/platformdirs/>`_ library to determine
168+
default directory locations. This means that default paths are **platform-specific**:
169+
170+
- **Linux**: Uses XDG Base Directory Specification paths (e.g., ``~/.config/borg``,
171+
``~/.cache/borg``, ``~/.local/share/borg``). `XDG env var`_ variables are honoured.
172+
- **macOS**: Uses native macOS directories (e.g., ``~/Library/Application Support/borg``,
173+
``~/Library/Caches/borg``). `XDG env var`_ variables are **not** honoured.
174+
- **Windows**: Uses Windows AppData directories (e.g., ``C:\Users\<user>\AppData\Roaming\borg``,
175+
``C:\Users\<user>\AppData\Local\borg``). `XDG env var`_ variables are **not** honoured.
176+
177+
On all platforms, you can override each directory individually using the specific environment
178+
variables described below. You can also set ``BORG_BASE_DIR`` to force borg to use
179+
``BORG_BASE_DIR/.config/borg``, ``BORG_BASE_DIR/.cache/borg``, etc., regardless of the platform.
180+
181+
Default directory locations by platform (when no ``BORG_*`` environment variables are set):
182+
183+
.. list-table::
184+
:header-rows: 1
185+
:widths: 15 25 30 30
186+
187+
* - Directory
188+
- Linux
189+
- macOS
190+
- Windows
191+
* - Config
192+
- ``~/.config/borg``
193+
- ``~/Library/Application Support/borg``
194+
- ``%APPDATA%\borg``
195+
* - Cache
196+
- ``~/.cache/borg``
197+
- ``~/Library/Caches/borg``
198+
- ``%LOCALAPPDATA%\borg\Cache``
199+
* - Data
200+
- ``~/.local/share/borg``
201+
- ``~/Library/Application Support/borg``
202+
- ``%LOCALAPPDATA%\borg``
203+
* - Runtime
204+
- ``/run/user/<uid>/borg``
205+
- ``~/Library/Caches/TemporaryItems/borg``
206+
- ``%TEMP%\borg``
207+
* - Keys
208+
- ``<config_dir>/keys``
209+
- ``<config_dir>/keys``
210+
- ``<config_dir>\keys``
211+
* - Security
212+
- ``<data_dir>/security``
213+
- ``<data_dir>/security``
214+
- ``<data_dir>\security``
215+
164216
BORG_BASE_DIR
165217
Defaults to ``$HOME`` or ``~$USER`` or ``~`` (in that order).
166218
If you want to move all borg-specific folders to a custom path at once, all you need to do is
167219
to modify ``BORG_BASE_DIR``: the other paths for cache, config etc. will adapt accordingly
168220
(assuming you didn't set them to a different custom value).
169221
BORG_CACHE_DIR
170-
Defaults to ``$BORG_BASE_DIR/.cache/borg``. If ``BORG_BASE_DIR`` is not explicitly set while
171-
`XDG env var`_ ``XDG_CACHE_HOME`` is set, then ``$XDG_CACHE_HOME/borg`` is being used instead.
222+
Defaults to the platform-specific cache directory (see table above).
223+
If ``BORG_BASE_DIR`` is set, defaults to ``$BORG_BASE_DIR/.cache/borg``.
224+
On Linux, `XDG env var`_ ``XDG_CACHE_HOME`` is also honoured if ``BORG_BASE_DIR`` is not set.
172225
This directory contains the local cache and might need a lot
173226
of space for dealing with big repositories. Make sure you're aware of the associated
174227
security aspects of the cache location: :ref:`cache_security`
175228
BORG_CONFIG_DIR
176-
Defaults to ``$BORG_BASE_DIR/.config/borg``. If ``BORG_BASE_DIR`` is not explicitly set while
177-
`XDG env var`_ ``XDG_CONFIG_HOME`` is set, then ``$XDG_CONFIG_HOME/borg`` is being used instead.
229+
Defaults to the platform-specific config directory (see table above).
230+
If ``BORG_BASE_DIR`` is set, defaults to ``$BORG_BASE_DIR/.config/borg``.
231+
On Linux, `XDG env var`_ ``XDG_CONFIG_HOME`` is also honoured if ``BORG_BASE_DIR`` is not set.
178232
This directory contains all borg configuration directories, see the FAQ
179233
for a security advisory about the data in this directory: :ref:`home_config_borg`
180234
BORG_DATA_DIR
181-
Defaults to ``$BORG_BASE_DIR/.local/share/borg``. If ``BORG_BASE_DIR`` is not explicitly set while
182-
`XDG env var`_ ``XDG_DATA_HOME`` is set, then ``$XDG_DATA_HOME/borg`` is being used instead.
235+
Defaults to the platform-specific data directory (see table above).
236+
If ``BORG_BASE_DIR`` is set, defaults to ``$BORG_BASE_DIR/.local/share/borg``.
237+
On Linux, `XDG env var`_ ``XDG_DATA_HOME`` is also honoured if ``BORG_BASE_DIR`` is not set.
183238
This directory contains all borg data directories, see the FAQ
184239
for a security advisory about the data in this directory: :ref:`home_data_borg`
185240
BORG_RUNTIME_DIR
186-
Defaults to ``$BORG_BASE_DIR/.cache/borg``. If ``BORG_BASE_DIR`` is not explicitly set while
187-
`XDG env var`_ ``XDG_RUNTIME_DIR`` is set, then ``$XDG_RUNTIME_DIR/borg`` is being used instead.
241+
Defaults to the platform-specific runtime directory (see table above).
242+
If ``BORG_BASE_DIR`` is set, defaults to ``$BORG_BASE_DIR/.cache/borg``.
243+
On Linux, `XDG env var`_ ``XDG_RUNTIME_DIR`` is also honoured if ``BORG_BASE_DIR`` is not set.
188244
This directory contains borg runtime files, like e.g. the socket file.
189245
BORG_SECURITY_DIR
190246
Defaults to ``$BORG_DATA_DIR/security``.

docs/usage/key.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ Examples
2828
Remember your passphrase. Your data will be inaccessible without it.
2929
Key updated
3030

31+
.. note::
32+
33+
The key file paths shown above are the defaults for Linux (``~/.config/borg/keys/``).
34+
On macOS, key files are stored in ``~/Library/Application Support/borg/keys/``.
35+
On Windows, they are stored in ``C:\Users\<user>\AppData\Roaming\borg\keys\``.
36+
See :ref:`env_vars` for details.
37+
38+
::
39+
3140
# Import a previously-exported key into the specified
3241
# key file (creating or overwriting the output key)
3342
# (keyfile repositories only)

docs/usage/repo-create.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Examples
2222
$ export BORG_REPO=ssh://user@hostname/~/backup
2323
# repokey: stores the encrypted key in <REPO_DIR>/config
2424
$ borg repo-create --encryption=repokey-aes-ocb
25-
# keyfile: stores the encrypted key in ~/.config/borg/keys/
25+
# keyfile: stores the encrypted key in the config dir's keys/ subdir
26+
# (e.g. ~/.config/borg/keys/ on Linux, ~/Library/Application Support/borg/keys/ on macOS)
2627
$ borg repo-create --encryption=keyfile-aes-ocb
2728

docs/usage/repo-create.rst.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ The easiest way to find out what is fastest is to run ``borg benchmark cpu``.
122122
the key will be stored in the repository (in ``repo_dir/config``).
123123

124124
`keyfile` modes: if you want "passphrase and having-the-key" security -
125-
the key will be stored in your home directory (in ``~/.config/borg/keys``).
125+
the key will be stored in the keys subdirectory of the borg config directory
126+
(e.g., ``~/.config/borg/keys`` on Linux, ``~/Library/Application Support/borg/keys``
127+
on macOS -- see :ref:`env_vars` for platform-specific default paths).
126128

127129
The following table is roughly sorted in order of preference, the better ones are
128130
in the upper part of the table, in the lower part is the old and/or unsafe(r) stuff:

docs/usage/transfer.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,41 @@ Examples
3030
$ borg --repo ssh://borg2@borgbackup/./tests/b20 transfer --upgrader=From12To20 \
3131
--other-repo ssh://borg2@borgbackup/./tests/b12 --dry-run
3232

33+
Keyfile considerations when upgrading from borg 1.x
34+
++++++++++++++++++++++++++++++++++++++++++++++++++++
35+
36+
If you are using a ``keyfile`` encryption mode (not ``repokey``), borg 2
37+
may not automatically find your borg 1.x key file, because the default
38+
key file directory has changed on some platforms due to the switch to
39+
the `platformdirs <https://pypi.org/project/platformdirs/>`_ library.
40+
41+
On **Linux**, there is typically no change -- both borg 1.x and borg 2
42+
use ``~/.config/borg/keys/``.
43+
44+
On **macOS**, borg 1.x stored key files in ``~/.config/borg/keys/``,
45+
but borg 2 defaults to ``~/Library/Application Support/borg/keys/``.
46+
47+
On **Windows**, borg 1.x used XDG-style paths (e.g. ``~/.config/borg/keys/``),
48+
while borg 2 defaults to ``C:\Users\<user>\AppData\Roaming\borg\keys\``.
49+
50+
If borg 2 cannot find your key file, you have several options:
51+
52+
1. **Copy the key file** from the old location to the new one.
53+
2. **Set BORG_KEYS_DIR** to point to the old key file directory::
54+
55+
export BORG_KEYS_DIR=~/.config/borg/keys
56+
57+
3. **Set BORG_KEY_FILE** to point directly to the specific key file::
58+
59+
export BORG_KEY_FILE=~/.config/borg/keys/your_key_file
60+
61+
4. **Set BORG_BASE_DIR** to force borg 2 to use the same base directory
62+
as borg 1.x::
63+
64+
export BORG_BASE_DIR=$HOME
65+
66+
This makes borg 2 use ``$HOME/.config/borg``, ``$HOME/.cache/borg``,
67+
etc., matching borg 1.x behaviour on all platforms.
68+
69+
See :ref:`env_vars` for more details on directory environment variables.
70+

0 commit comments

Comments
 (0)