bdbackup 0.7.0__tar.gz → 0.7.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bdbackup-0.7.0 → bdbackup-0.7.1}/PKG-INFO +6 -1
- {bdbackup-0.7.0 → bdbackup-0.7.1}/README.md +5 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/config.toml.example +3 -2
- bdbackup-0.7.1/contrib/systemd/bdbackup-incremental@.service +11 -0
- bdbackup-0.7.1/contrib/systemd/bdbackup-incremental@.timer +10 -0
- bdbackup-0.7.1/contrib/systemd/bdbackup@.service +11 -0
- bdbackup-0.7.1/contrib/systemd/bdbackup@.timer +10 -0
- bdbackup-0.7.1/docs/README_SYSTEMD.md +138 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/docs/README_XTRABACKUP.md +6 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/pyproject.toml +2 -1
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/AGENTS.md +1 -1
- bdbackup-0.7.1/tests/test_systemd_units.py +111 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/.gitignore +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/LICENSE +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/__init__.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/backends.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/cli.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/config.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/engines.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/filebackup.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/gfs/__init__.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/gfs/actions.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/gfs/policy.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/gfs/runner.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/gfs/stages.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/gfs/store.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/gfs/structure.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/history.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/ledger.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/mysql/__init__.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/mysql/helpers.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/mysql/mysqldump.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/mysql/xtrabackup.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/recovery.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/templates/__init__.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/templates/_matching.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/templates/python_dev.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/utils.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/bdbackup/validation.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/docs/README_ENGINES.md +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/docs/README_FILE.md +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/docs/README_GFS.md +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/docs/README_MYSQLDUMP.md +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/scripts/check_release.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/scripts/integration_mysql.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/scripts/integration_physical.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/scripts/smoke_install.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/template.txt +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/__init__.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/conftest.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_architecture.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_cli_reshape.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_correctness.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_encryption.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_engine_conditions.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_engines.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_gfs_config.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_gfs_init.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_gfs_policy.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_gfs_run.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_gfs_store.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_helpers.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_history.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_import.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_ledger.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_performance.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_release_fixes.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_run_selector.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_safety_nets.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_security.py +0 -0
- {bdbackup-0.7.0 → bdbackup-0.7.1}/tests/test_templates.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bdbackup
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.1
|
|
4
4
|
Summary: MySQL, MariaDB and file backups with mysqldump, Percona XtraBackup, MariaDB Backup and tar: verification, GFS rotation and guided restore
|
|
5
5
|
Project-URL: Homepage, https://github.com/ayder/bdbackup
|
|
6
6
|
Project-URL: Repository, https://github.com/ayder/bdbackup
|
|
@@ -73,6 +73,7 @@ run from cron.
|
|
|
73
73
|
| [MySQL and MariaDB physical backups with Percona XtraBackup and MariaDB Backup](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md) | xtrabackup jobs, full and incremental backups, encryption, preparing a recovery copy, engine pruning |
|
|
74
74
|
| [GFS (grandfather-father-son) backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md) | stages, preparing stage directories, safety rules, run and step logs, ledger copies |
|
|
75
75
|
| [Custom backup engines (plugins)](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md) | the engine registry and writing your own engine |
|
|
76
|
+
| [Running xtrabackup jobs with systemd timers](https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md) | service and timer templates, the mysql account, schedules, CPU, I/O and memory limits |
|
|
76
77
|
| [Annotated configuration](https://github.com/ayder/bdbackup/blob/master/config.toml.example) | every config key with a comment |
|
|
77
78
|
|
|
78
79
|
## Support and safety
|
|
@@ -239,6 +240,10 @@ Times use the cron daemon's timezone, and separate lines do not wait for each
|
|
|
239
240
|
other: leave enough time for backups before GFS. Add `--dry-run` to the GFS line
|
|
240
241
|
until its report looks right.
|
|
241
242
|
|
|
243
|
+
xtrabackup jobs can run from systemd timers instead, which also stop the backup
|
|
244
|
+
tool if bdbackup dies and add per-job limits: see
|
|
245
|
+
[Running xtrabackup jobs with systemd timers](https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md).
|
|
246
|
+
|
|
242
247
|
### Validate configuration and permissions
|
|
243
248
|
|
|
244
249
|
Check all configured jobs without creating a backup or running retention:
|
|
@@ -39,6 +39,7 @@ run from cron.
|
|
|
39
39
|
| [MySQL and MariaDB physical backups with Percona XtraBackup and MariaDB Backup](https://github.com/ayder/bdbackup/blob/master/docs/README_XTRABACKUP.md) | xtrabackup jobs, full and incremental backups, encryption, preparing a recovery copy, engine pruning |
|
|
40
40
|
| [GFS (grandfather-father-son) backup rotation](https://github.com/ayder/bdbackup/blob/master/docs/README_GFS.md) | stages, preparing stage directories, safety rules, run and step logs, ledger copies |
|
|
41
41
|
| [Custom backup engines (plugins)](https://github.com/ayder/bdbackup/blob/master/docs/README_ENGINES.md) | the engine registry and writing your own engine |
|
|
42
|
+
| [Running xtrabackup jobs with systemd timers](https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md) | service and timer templates, the mysql account, schedules, CPU, I/O and memory limits |
|
|
42
43
|
| [Annotated configuration](https://github.com/ayder/bdbackup/blob/master/config.toml.example) | every config key with a comment |
|
|
43
44
|
|
|
44
45
|
## Support and safety
|
|
@@ -205,6 +206,10 @@ Times use the cron daemon's timezone, and separate lines do not wait for each
|
|
|
205
206
|
other: leave enough time for backups before GFS. Add `--dry-run` to the GFS line
|
|
206
207
|
until its report looks right.
|
|
207
208
|
|
|
209
|
+
xtrabackup jobs can run from systemd timers instead, which also stop the backup
|
|
210
|
+
tool if bdbackup dies and add per-job limits: see
|
|
211
|
+
[Running xtrabackup jobs with systemd timers](https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md).
|
|
212
|
+
|
|
208
213
|
### Validate configuration and permissions
|
|
209
214
|
|
|
210
215
|
Check all configured jobs without creating a backup or running retention:
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
# registered by a dropped-in module (e.g. a future xtrabackup80 or mysql-shell).
|
|
17
17
|
# Any job may set active = false to pause it: `run -j` then refuses it (exit 2)
|
|
18
18
|
# and --validate names it as not checked. Schedule jobs with your own crontab
|
|
19
|
-
# lines (see the README, "Scheduling with cron")
|
|
20
|
-
# settings/access/grants
|
|
19
|
+
# lines (see the README, "Scheduling with cron"); xtrabackup jobs can use systemd
|
|
20
|
+
# timers instead (docs/README_SYSTEMD.md). --validate checks settings/access/grants
|
|
21
|
+
# without backups.
|
|
21
22
|
# Other keys (except type, active and restore_root) are passed to the backend
|
|
22
23
|
# constructor (FileBackup / bdbackup.mysql.MySQLBackup / bdbackup.mysql.XtraBackup),
|
|
23
24
|
# so key names use Python-style underscores (e.g. exclude_templates).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=bdbackup incremental backup of job %i
|
|
3
|
+
Documentation=https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md
|
|
4
|
+
|
|
5
|
+
[Service]
|
|
6
|
+
Type=oneshot
|
|
7
|
+
User=mysql
|
|
8
|
+
Group=mysql
|
|
9
|
+
KillMode=control-group
|
|
10
|
+
Environment=BDBACKUP_CONFIG=/etc/bdbackup/config.toml
|
|
11
|
+
ExecStart=bdbackup run -c ${BDBACKUP_CONFIG} -j %i --incremental
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=Schedule of bdbackup incremental backup of job %i
|
|
3
|
+
Documentation=https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md
|
|
4
|
+
|
|
5
|
+
[Timer]
|
|
6
|
+
Unit=bdbackup-incremental@%i.service
|
|
7
|
+
Persistent=false
|
|
8
|
+
|
|
9
|
+
[Install]
|
|
10
|
+
WantedBy=timers.target
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=bdbackup full backup of job %i
|
|
3
|
+
Documentation=https://github.com/ayder/bdbackup/blob/master/docs/README_SYSTEMD.md
|
|
4
|
+
|
|
5
|
+
[Service]
|
|
6
|
+
Type=oneshot
|
|
7
|
+
User=mysql
|
|
8
|
+
Group=mysql
|
|
9
|
+
KillMode=control-group
|
|
10
|
+
Environment=BDBACKUP_CONFIG=/etc/bdbackup/config.toml
|
|
11
|
+
ExecStart=bdbackup run -c ${BDBACKUP_CONFIG} -j %i
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Running xtrabackup jobs with systemd timers
|
|
2
|
+
|
|
3
|
+
bdbackup can run xtrabackup jobs as systemd units instead of cron lines. If
|
|
4
|
+
bdbackup dies, even from `kill -9`, systemd stops the backup tool with it, so no
|
|
5
|
+
orphan keeps loading the server. Each job can have its own CPU, I/O and memory
|
|
6
|
+
limits, and status and logs come from `systemctl` and `journalctl`.
|
|
7
|
+
|
|
8
|
+
Cron keeps working, and bdbackup does not install units. Other job types stay on
|
|
9
|
+
cron.
|
|
10
|
+
|
|
11
|
+
Part of the [bdbackup documentation](../README.md).
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- Linux with systemd and cgroup v2. Installing the units needs root; backups run
|
|
16
|
+
as the `mysql` account, which owns the datadir.
|
|
17
|
+
- Job names that need no systemd escaping. `mysql-prod` works; a name with a space
|
|
18
|
+
does not.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
Fetch the units for your installed version:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
version=$(bdbackup --version | awk '{print $NF}')
|
|
26
|
+
for unit in bdbackup@.service bdbackup-incremental@.service \
|
|
27
|
+
bdbackup@.timer bdbackup-incremental@.timer; do
|
|
28
|
+
sudo curl -fsSLo "/etc/systemd/system/$unit" \
|
|
29
|
+
"https://raw.githubusercontent.com/ayder/bdbackup/v$version/contrib/systemd/$unit"
|
|
30
|
+
done
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
systemd looks for `bdbackup` in its standard paths. If you installed it in a
|
|
34
|
+
virtual environment, or with pipx or uv, link it:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
sudo ln -s "$(command -v bdbackup)" /usr/local/bin/bdbackup
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The link's target and the environment behind it must be readable by `mysql`. One
|
|
41
|
+
under `/root` or a home directory usually is not, so install it under `/opt`.
|
|
42
|
+
|
|
43
|
+
The units read `/etc/bdbackup/config.toml`. It holds passwords, and `mysql` must
|
|
44
|
+
be able to read it:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
sudo chown root:mysql /etc/bdbackup/config.toml
|
|
48
|
+
sudo chmod 640 /etc/bdbackup/config.toml
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Give `mysql` the `backup_root`, the directory of the history database, the
|
|
52
|
+
recovery root and any encryption key file. If cron ran this job as root, change
|
|
53
|
+
the owner of everything already in `backup_root`, including its backups and lock
|
|
54
|
+
file. `--validate` does not look inside it, and a `mysql` run fails on what it
|
|
55
|
+
cannot read:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
sudo chown -R mysql:mysql /backup/mysql/production
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Then check its access:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
sudo -u mysql /usr/local/bin/bdbackup run -c /etc/bdbackup/config.toml --validate -j mysql-prod
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
For another config path or account, set `Environment=BDBACKUP_CONFIG=...`, `User=`
|
|
68
|
+
and `Group=` in a drop-in.
|
|
69
|
+
|
|
70
|
+
## Schedule
|
|
71
|
+
|
|
72
|
+
The timers have no default schedule, so set one before enabling them. For a weekly
|
|
73
|
+
full and daily incrementals of `mysql-prod`:
|
|
74
|
+
|
|
75
|
+
```ini
|
|
76
|
+
# /etc/systemd/system/bdbackup@mysql-prod.timer.d/schedule.conf
|
|
77
|
+
[Timer]
|
|
78
|
+
OnCalendar=Sun 02:00
|
|
79
|
+
|
|
80
|
+
# /etc/systemd/system/bdbackup-incremental@mysql-prod.timer.d/schedule.conf
|
|
81
|
+
[Timer]
|
|
82
|
+
OnCalendar=Mon..Sat 02:00
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
sudo systemctl daemon-reload
|
|
87
|
+
sudo systemctl enable --now bdbackup@mysql-prod.timer bdbackup-incremental@mysql-prod.timer
|
|
88
|
+
systemctl list-timers 'bdbackup*'
|
|
89
|
+
journalctl -u 'bdbackup*@mysql-prod.service'
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Times use the host's timezone. A backup missed while the host was down does not
|
|
93
|
+
run at boot; add `Persistent=true` to the drop-in to change that.
|
|
94
|
+
|
|
95
|
+
Remove the job's cron lines when you enable its timers.
|
|
96
|
+
Never run one job from both.
|
|
97
|
+
|
|
98
|
+
## Limits
|
|
99
|
+
|
|
100
|
+
Limits go in a drop-in for each mode, so a full and an incremental can differ:
|
|
101
|
+
|
|
102
|
+
```ini
|
|
103
|
+
# /etc/systemd/system/bdbackup@mysql-prod.service.d/limits.conf
|
|
104
|
+
[Service]
|
|
105
|
+
MemoryHigh=1500M
|
|
106
|
+
MemorySwapMax=0
|
|
107
|
+
CPUQuota=200%
|
|
108
|
+
IOReadBandwidthMax=/dev/nvme0n1 200M
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Run `systemctl daemon-reload` after a change. A limit covers the whole job,
|
|
112
|
+
including the checksum bdbackup computes after the tool exits.
|
|
113
|
+
|
|
114
|
+
- **Start with `MemoryHigh=`.** xtrabackup's reads skip the page cache, but its
|
|
115
|
+
output and the checksum read fill it, and that memory is taken from mysqld. As a
|
|
116
|
+
guide, 1500M for a full and 1024M for an incremental ran clean on a 7.75 GiB host.
|
|
117
|
+
- **Prefer `MemoryHigh=` to `MemoryMax=`.** `MemoryMax=` kills the job and leaves a
|
|
118
|
+
`running` row in history.
|
|
119
|
+
- **`IOReadBandwidthMax=` and `IOWriteBandwidthMax=`** take a device path.
|
|
120
|
+
`IOWeight=` needs I/O scheduler or `io.cost` support, which NVMe setups often lack.
|
|
121
|
+
- **Do not throttle too hard.** A slower backup has more redo to follow. If redo wraps
|
|
122
|
+
before the tool reads it, the backup fails.
|
|
123
|
+
- **Limits do not help with waits on the backup lock,** which happen inside mysqld.
|
|
124
|
+
|
|
125
|
+
## Overlapping runs
|
|
126
|
+
|
|
127
|
+
A timer does not start a second copy of a unit that is still running. Full and
|
|
128
|
+
incremental are separate units, so bdbackup's lock decides between them: the second
|
|
129
|
+
exits 3 and shows as a failed unit, which keeps a stuck lock visible. If they overlap
|
|
130
|
+
on purpose, add `SuccessExitStatus=3` to the `[Service]` drop-in.
|
|
131
|
+
|
|
132
|
+
## What stays behind after a hard kill
|
|
133
|
+
|
|
134
|
+
After `kill -9` the tool stops, but bdbackup cannot clean up. The `.tmp` directory
|
|
135
|
+
stays in `backup_root`, the history row stays `running`, and the temporary option file
|
|
136
|
+
holding the password stays in the temp directory, readable only by `mysql`. The backup
|
|
137
|
+
chain is not affected, because a backup is committed only when its `.tmp` directory is
|
|
138
|
+
renamed. Remove these by hand.
|
|
@@ -156,3 +156,9 @@ See [Percona's encryption documentation](https://docs.percona.com/percona-xtraba
|
|
|
156
156
|
XtraBackup/MariaDB backups produce a prepared recovery directory, including
|
|
157
157
|
prerequisite increments. The destination must be outside the backup root.
|
|
158
158
|
Server ownership, copy-back, and startup remain administrator actions.
|
|
159
|
+
|
|
160
|
+
## Scheduling
|
|
161
|
+
|
|
162
|
+
Run xtrabackup jobs from [cron](../README.md#scheduling-with-cron) or from
|
|
163
|
+
[systemd timers](README_SYSTEMD.md), which add per-job limits and stop the backup
|
|
164
|
+
tool if bdbackup dies.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bdbackup"
|
|
7
|
-
version = "0.7.
|
|
7
|
+
version = "0.7.1"
|
|
8
8
|
description = "MySQL, MariaDB and file backups with mysqldump, Percona XtraBackup, MariaDB Backup and tar: verification, GFS rotation and guided restore"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -62,6 +62,7 @@ include = [
|
|
|
62
62
|
"/config.toml.example",
|
|
63
63
|
"/template.txt",
|
|
64
64
|
"/scripts",
|
|
65
|
+
"/contrib",
|
|
65
66
|
]
|
|
66
67
|
|
|
67
68
|
[tool.ruff]
|
|
@@ -123,4 +123,4 @@ here and commits it with the candidate before calling the gate; the gate agent n
|
|
|
123
123
|
|
|
124
124
|
| Baseline | Kind | Current value | Runner | Measured at |
|
|
125
125
|
|---|---|---|---|---|
|
|
126
|
-
| Unit test count | inventory |
|
|
126
|
+
| Unit test count | inventory | 371 passed | `.venv/bin/python -m pytest -q` | `3c4a894` |
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""The shipped systemd units keep their promised settings and match the real CLI."""
|
|
2
|
+
|
|
3
|
+
import configparser
|
|
4
|
+
import shlex
|
|
5
|
+
import tomllib
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
from click.testing import CliRunner
|
|
10
|
+
|
|
11
|
+
from bdbackup.cli import main
|
|
12
|
+
|
|
13
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
14
|
+
UNITS = ROOT / "contrib" / "systemd"
|
|
15
|
+
SERVICES = ["bdbackup@.service", "bdbackup-incremental@.service"]
|
|
16
|
+
TIMERS = {
|
|
17
|
+
"bdbackup@.timer": "bdbackup@%i.service",
|
|
18
|
+
"bdbackup-incremental@.timer": "bdbackup-incremental@%i.service",
|
|
19
|
+
}
|
|
20
|
+
LEFT_TO_DROP_INS = {
|
|
21
|
+
"CPUQuota", "CPUWeight", "IOWeight", "IOReadBandwidthMax", "IOWriteBandwidthMax",
|
|
22
|
+
"MemoryHigh", "MemoryMax", "MemorySwapMax", "PrivateTmp", "ProtectSystem", "ProtectHome",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def unit(name: str) -> configparser.ConfigParser:
|
|
27
|
+
parser = configparser.ConfigParser(interpolation=None, strict=False)
|
|
28
|
+
parser.optionxform = str
|
|
29
|
+
parser.read_string((UNITS / name).read_text())
|
|
30
|
+
return parser
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.parametrize("name", SERVICES)
|
|
34
|
+
def test_service_runs_as_mysql_and_dies_as_one_cgroup(name):
|
|
35
|
+
service = unit(name)["Service"]
|
|
36
|
+
assert service["Type"] == "oneshot"
|
|
37
|
+
assert service["User"] == "mysql"
|
|
38
|
+
assert service["Group"] == "mysql"
|
|
39
|
+
assert service["KillMode"] == "control-group"
|
|
40
|
+
assert service["Environment"] == "BDBACKUP_CONFIG=/etc/bdbackup/config.toml"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@pytest.mark.parametrize("name", [*SERVICES, *TIMERS])
|
|
44
|
+
def test_job_name_is_not_unescaped(name):
|
|
45
|
+
"""%I would turn mysql-prod into mysql/prod."""
|
|
46
|
+
assert "%i" in (UNITS / name).read_text()
|
|
47
|
+
assert "%I" not in (UNITS / name).read_text()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@pytest.mark.parametrize("name", SERVICES)
|
|
51
|
+
def test_limits_and_sandboxing_are_left_to_drop_ins(name):
|
|
52
|
+
assert LEFT_TO_DROP_INS.isdisjoint(unit(name)["Service"])
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@pytest.mark.parametrize(("name", "target"), TIMERS.items())
|
|
56
|
+
def test_timer_has_no_default_schedule_and_no_catch_up(name, target):
|
|
57
|
+
timer = unit(name)
|
|
58
|
+
assert timer["Timer"]["Unit"] == target
|
|
59
|
+
assert timer["Timer"]["Persistent"] == "false"
|
|
60
|
+
assert "OnCalendar" not in timer["Timer"]
|
|
61
|
+
assert timer["Install"]["WantedBy"] == "timers.target"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@pytest.mark.parametrize(
|
|
65
|
+
("name", "exit_code", "output"),
|
|
66
|
+
[
|
|
67
|
+
("bdbackup@.service", 0, "Dry run; would take a full backup"),
|
|
68
|
+
# Past argument parsing; a dry incremental needs a full, so a usage error (2) is the bug.
|
|
69
|
+
("bdbackup-incremental@.service", 1, ""),
|
|
70
|
+
],
|
|
71
|
+
)
|
|
72
|
+
def test_exec_start_is_a_command_the_cli_accepts(tmp_path, name, exit_code, output):
|
|
73
|
+
config = tmp_path / "config.toml"
|
|
74
|
+
config.write_text('[mysql-prod]\ntype="xtrabackup"\nbackup_root="backups"\n')
|
|
75
|
+
command = unit(name)["Service"]["ExecStart"]
|
|
76
|
+
command = command.replace("${BDBACKUP_CONFIG}", str(config)).replace("%i", "mysql-prod")
|
|
77
|
+
program, *args = shlex.split(command)
|
|
78
|
+
assert program == "bdbackup"
|
|
79
|
+
result = CliRunner().invoke(main, [*args, "--dry-run"])
|
|
80
|
+
assert result.exit_code == exit_code
|
|
81
|
+
assert output in result.output
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_sdist_carries_the_units():
|
|
85
|
+
project = tomllib.loads((ROOT / "pyproject.toml").read_text())
|
|
86
|
+
assert "/contrib" in project["tool"]["hatch"]["build"]["targets"]["sdist"]["include"]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@pytest.mark.parametrize(
|
|
90
|
+
"fact",
|
|
91
|
+
[
|
|
92
|
+
"ln -s", # the binary link: without it the unit fails with 203/EXEC
|
|
93
|
+
"chmod 640", # the config holds passwords and mysql must read it
|
|
94
|
+
"OnCalendar=", # the schedule comes before enable
|
|
95
|
+
"--validate", # proves the mysql account's access before a first run
|
|
96
|
+
"MemoryHigh=", # the first limit to set
|
|
97
|
+
"cgroup v2",
|
|
98
|
+
"Never run one job from both",
|
|
99
|
+
"chown -R", # root-made backups and lock file block a mysql run; --validate misses them
|
|
100
|
+
"sudo -u mysql /usr/local/bin/bdbackup", # sudo's secure_path may omit /usr/local/bin
|
|
101
|
+
"under `/opt`", # a venv under /root or a home fails with 203/EXEC despite the link
|
|
102
|
+
"recovery root", # --validate fails until mysql can write it
|
|
103
|
+
],
|
|
104
|
+
)
|
|
105
|
+
def test_systemd_document_states_what_an_operator_trips_on(fact):
|
|
106
|
+
assert fact in (ROOT / "docs" / "README_SYSTEMD.md").read_text()
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@pytest.mark.parametrize("document", ["README.md", "CLAUDE.md"])
|
|
110
|
+
def test_systemd_document_is_linked(document):
|
|
111
|
+
assert "README_SYSTEMD.md" in (ROOT / document).read_text()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|