Skip to content

Commit 66aad2e

Browse files
Merge pull request #10545 from ThomasWaldmann/docs-automated-local-multi-disk
docs: automated-local: support multiple backup drives, fixes #9834
2 parents 2a0e572 + dae6a2a commit 66aad2e

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

‎docs/deployment/automated-local.rst‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ systemd and udev.
1414
Overview
1515
--------
1616

17-
A udev rule is created to trigger on the addition of block devices. The rule contains a tag
18-
that triggers systemd to start a one-shot service. The one-shot service executes a script in
17+
A udev rule is created to trigger on the addition of a filesystem on one of your registered
18+
backup drives. The rule contains a tag that triggers systemd to start a one-shot service. The one-shot service executes a script in
1919
the standard systemd service environment, which automatically captures stdout/stderr and
2020
logs it to the journal.
2121

@@ -29,13 +29,16 @@ Configuring the system
2929
First, create the ``/etc/backups`` directory (as root).
3030
All configuration goes into this directory.
3131

32-
Find out the ID of the partition table of your backup disk (here assumed to be /dev/sdz)::
32+
Then, create an empty ``/etc/backups/80-backup.rules`` file. It will contain one line per
33+
backup drive, which you will add when adding backup drives (see below). Each line looks like
34+
this (all on one line)::
3335

34-
lsblk --fs -o +PTUUID /dev/sdz
36+
ACTION=="add", SUBSYSTEM=="block", ENV{ID_FS_UUID}=="<filesystem UUID>", TAG+="systemd", ENV{SYSTEMD_WANTS}+="automatic-backup.service"
3537

36-
Then, create ``/etc/backups/80-backup.rules`` with the following content (all on one line)::
37-
38-
ACTION=="add", SUBSYSTEM=="block", ENV{ID_PART_TABLE_UUID}=="<the PTUUID you just noted>", TAG+="systemd", ENV{SYSTEMD_WANTS}+="automatic-backup.service"
38+
The rule matches the filesystem on the backup drive by its UUID, which is the same UUID
39+
that you will also record in ``/etc/backups/backup.disks``. A single line can also match
40+
several backup drives, if you separate their UUIDs with ``|``, e.g.
41+
``ENV{ID_FS_UUID}=="<UUID 1>|<UUID 2>"``.
3942

4043
The "systemd" tag in conjunction with the SYSTEMD_WANTS environment variable has systemd
4144
launch the "automatic-backup" service, which we will create next, as the
@@ -54,12 +57,7 @@ modify it to suit your needs (e.g., more backup sets, dumping databases, etc.).
5457
5558
#!/bin/bash -ue
5659
57-
# The udev rule is not terribly accurate and may trigger our service before
58-
# the kernel has finished probing partitions. Sleep for a bit to ensure
59-
# the kernel is done.
60-
#
61-
# This can be avoided by using a more precise udev rule, e.g. matching
62-
# a specific hardware path and partition.
60+
# Give the system a moment to settle after the backup drive was connected.
6361
sleep 5
6462
6563
#
@@ -186,6 +184,13 @@ Find the UUID of the filesystem on which backups should be stored::
186184

187185
Record the UUID in the ``/etc/backups/backup.disks`` file.
188186

187+
Add a line for this UUID to ``/etc/backups/80-backup.rules`` (see above), so that connecting
188+
the drive starts the ``automatic-backup`` service, and reload the udev rules::
189+
190+
udevadm control --reload
191+
192+
Every backup drive needs both: its UUID in ``backup.disks`` and a matching udev rule.
193+
189194
Mount the drive at /mnt/backup.
190195

191196
Create a Borg repository at the location indicated by ``TARGET``::

0 commit comments

Comments
 (0)