Restoring a specific database conflicts with creating a backup that includes all databases #560

Closed
opened 2022-07-05 18:07:38 +00:00 by Alex789 · 4 comments

What I'm trying to do and why

I made borgmatic create a backup including all databases by writing "- name: all" in the /etc/borgmatic/config.yaml file.
This is according to the guideline "If you want to dump all databases on a host, use all for the database name".

I have a script that automatically creates new databases. The "- name: all" option comes in handy. Otherwise, I would have to update the config file everytime I create a new database.

Steps to reproduce

Make a backup including all databases with this config:

location:
    source_directories:
         - /var/www/html
         - /etc
         - /root
         - /var/log/syslog*
    repositories:
         - blablabla@blabla.repo.borgbase.com:repo
    exclude_patterns:
        - '*.pyc'
        - /home/*/.cache
    exclude_caches: true
    exclude_if_present:
        - .nobackup

storage:
    encryption_passphrase: "blablablablabla"
    ssh_command: ssh -i /root/.ssh/id_ed25519_blabla
    archive_name_format: '{hostname}-{now}'

retention:
    keep_within: 24H
    keep_daily: 7
    keep_weekly: 4
    keep_monthly: 6
    keep_yearly: 1

consistency:
    checks:
        - name: repository
        - name: archives
          frequency: 2 weeks

hooks:
  mysql_databases:
        - name: all
  healthchecks:
      ping_url: https://hc-ping.com/blablablabla

Run borgmatic create
Delete the database using mysql> drop database at409171;
Restore the database using borgmatic restore --archive blabla-2022-07-05T15:03:38 --database at409171

Actual behavior

After restoring the database, the database is still not there. (mysql> show databases; doesn't show the database.)

I get this output:

borgmatic restore --archive blabla-2022-07-05T15:03:38 --database at409171 -v 2
Ensuring legacy configuration is upgraded
borg --version --debug --show-rc
blablabla@blabla.repo.borgbase.com:repo: Restoring databases from archive blabla-2022-07-05T15:03:38
blablabla@blabla.repo.borgbase.com:repo: Calling mysql_databases hook function remove_database_dumps
blablabla@blabla.repo.borgbase.com:repo: Removing MySQL database dumps
blablabla@blabla.repo.borgbase.com:repo: Calling mysql_databases hook function make_database_dump_pattern
borg extract --debug --list --show-rc --stdout blablabla@blabla.repo.borgbase.com:repo::blabla-2022-07-05T15:03:38 sh:root/.borgmatic/mysql_databases/*/at409171 > 
blablabla@blabla.repo.borgbase.com:repo: Calling mysql_databases hook function restore_database_dump
blablabla@blabla.repo.borgbase.com:repo: Restoring MySQL database at409171
mysql --batch < 3
using builtin fallback logging configuration
35 self tests completed in 0.12 seconds
SSH command line: ['ssh', '-i', '/root/.ssh/id_ed25519_blabla', 'blablabla@blabla.repo.borgbase.com', 'borg', 'serve', '--umask=077', '--debug']
Remote: using builtin fallback logging configuration
Remote: borg selftest disabled via BORG_SELFTEST env variable
Remote: using builtin fallback logging configuration
Remote: Initialized logging system for JSON-based protocol
Remote: Resolving repository path b'repo'
Remote: Resolved repository path to '/srv/repos/blabla/repo'
Remote: Verified integrity of /srv/repos/blabla/repo/index.815
TAM-verified manifest
security: read previous location 'ssh://blablabla@blabla.repo.borgbase.com/./repo'
security: read manifest timestamp '2022-07-05T16:48:42.003492'
security: determined newest manifest timestamp as 2022-07-05T16:48:42.003492
security: repository checks ok, allowing access
Include pattern 'root/.borgmatic/mysql_databases/*/at409171' never matched.
RemoteRepository: 5.72 kB bytes sent, 4.51 MB bytes received, 113 messages sent
terminating with warning status, rc 1
blablabla@blabla.repo.borgbase.com:repo: Calling mysql_databases hook function remove_database_dumps
blablabla@blabla.repo.borgbase.com:repo: Removing MySQL database dumps

summary:
/etc/borgmatic/config.yaml: Successfully ran configuration file

There is no error notification or similar.

Note the line: Include pattern 'root/.borgmatic/mysql_databases/*/at409171' never matched.
It seems that borgmatic is searching for a file called at409171 (name of the database).
However, when I normally extract the repo, I'll find the dumps of all the databases in one common file called root/.borgmatic/mysql_databases/localhost/all.

Expected behavior

The database should be restored.
If the database can't be restored (file not found), an error notification should be displayed.

Other notes / implementation ideas

When creating the backup, dump the databases in separate files for each database.

Environment

borgmatic version: 1.6.5

borgmatic installation method: sudo pip install --user --upgrade borgmatic

Borg version: borg 1.1.15

Python version: Python 3.8.10

Database version: mysql Ver 8.0.29-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))

operating system and version: Ubuntu 20.04.4 LTS

#### What I'm trying to do and why I made borgmatic create a backup including all databases by writing "- name: all" in the /etc/borgmatic/config.yaml file. This is according to the [guideline](https://https://torsion.org/borgmatic/docs/how-to/backup-your-databases/#database-dump-hooks) "If you want to dump all databases on a host, use all for the database name". I have a script that automatically creates new databases. The "- name: all" option comes in handy. Otherwise, I would have to update the config file everytime I create a new database. #### Steps to reproduce Make a backup including all databases with this config: ``` location: source_directories: - /var/www/html - /etc - /root - /var/log/syslog* repositories: - blablabla@blabla.repo.borgbase.com:repo exclude_patterns: - '*.pyc' - /home/*/.cache exclude_caches: true exclude_if_present: - .nobackup storage: encryption_passphrase: "blablablablabla" ssh_command: ssh -i /root/.ssh/id_ed25519_blabla archive_name_format: '{hostname}-{now}' retention: keep_within: 24H keep_daily: 7 keep_weekly: 4 keep_monthly: 6 keep_yearly: 1 consistency: checks: - name: repository - name: archives frequency: 2 weeks hooks: mysql_databases: - name: all healthchecks: ping_url: https://hc-ping.com/blablablabla ``` Run `borgmatic create` Delete the database using `mysql> drop database at409171; ` Restore the database using `borgmatic restore --archive blabla-2022-07-05T15:03:38 --database at409171` #### Actual behavior After restoring the database, the database is still not there. (`mysql> show databases;` doesn't show the database.) I get this output: ``` borgmatic restore --archive blabla-2022-07-05T15:03:38 --database at409171 -v 2 Ensuring legacy configuration is upgraded borg --version --debug --show-rc blablabla@blabla.repo.borgbase.com:repo: Restoring databases from archive blabla-2022-07-05T15:03:38 blablabla@blabla.repo.borgbase.com:repo: Calling mysql_databases hook function remove_database_dumps blablabla@blabla.repo.borgbase.com:repo: Removing MySQL database dumps blablabla@blabla.repo.borgbase.com:repo: Calling mysql_databases hook function make_database_dump_pattern borg extract --debug --list --show-rc --stdout blablabla@blabla.repo.borgbase.com:repo::blabla-2022-07-05T15:03:38 sh:root/.borgmatic/mysql_databases/*/at409171 > blablabla@blabla.repo.borgbase.com:repo: Calling mysql_databases hook function restore_database_dump blablabla@blabla.repo.borgbase.com:repo: Restoring MySQL database at409171 mysql --batch < 3 using builtin fallback logging configuration 35 self tests completed in 0.12 seconds SSH command line: ['ssh', '-i', '/root/.ssh/id_ed25519_blabla', 'blablabla@blabla.repo.borgbase.com', 'borg', 'serve', '--umask=077', '--debug'] Remote: using builtin fallback logging configuration Remote: borg selftest disabled via BORG_SELFTEST env variable Remote: using builtin fallback logging configuration Remote: Initialized logging system for JSON-based protocol Remote: Resolving repository path b'repo' Remote: Resolved repository path to '/srv/repos/blabla/repo' Remote: Verified integrity of /srv/repos/blabla/repo/index.815 TAM-verified manifest security: read previous location 'ssh://blablabla@blabla.repo.borgbase.com/./repo' security: read manifest timestamp '2022-07-05T16:48:42.003492' security: determined newest manifest timestamp as 2022-07-05T16:48:42.003492 security: repository checks ok, allowing access Include pattern 'root/.borgmatic/mysql_databases/*/at409171' never matched. RemoteRepository: 5.72 kB bytes sent, 4.51 MB bytes received, 113 messages sent terminating with warning status, rc 1 blablabla@blabla.repo.borgbase.com:repo: Calling mysql_databases hook function remove_database_dumps blablabla@blabla.repo.borgbase.com:repo: Removing MySQL database dumps summary: /etc/borgmatic/config.yaml: Successfully ran configuration file ``` There is no error notification or similar. **Note the line**: `Include pattern 'root/.borgmatic/mysql_databases/*/at409171' never matched.` It seems that borgmatic is searching for a file called at409171 (name of the database). However, when I normally extract the repo, I'll find the dumps of all the databases in one common file called `root/.borgmatic/mysql_databases/localhost/all`. #### Expected behavior The database should be restored. If the database can't be restored (file not found), an error notification should be displayed. #### Other notes / implementation ideas When creating the backup, dump the databases in separate files for each database. #### Environment **borgmatic version:** 1.6.5 **borgmatic installation method:** sudo pip install --user --upgrade borgmatic **Borg version:** borg 1.1.15 **Python version:** Python 3.8.10 **Database version:** mysql Ver 8.0.29-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu)) **operating system and version:** Ubuntu 20.04.4 LTS
Owner

Thanks for filing this! Yeah, borgmatic restores are currently all-or-nothing when the database is all. Your idea for supporting a single database restore with separate files is probably the way to go. See #438 for a similar idea.

Thanks for filing this! Yeah, borgmatic restores are currently all-or-nothing when the database is `all`. Your idea for supporting a single database restore with separate files is probably the way to go. See #438 for a similar idea.
witten added the
bug
label 2022-07-05 18:13:59 +00:00
Owner

If the database can't be restored (file not found), an error notification should be displayed.

This part of the ticket is done in master and will be part of the next release. I'm still trying to figure out what to do for the rest of the ticket.

> If the database can't be restored (file not found), an error notification should be displayed. This part of the ticket is done in master and will be part of the next release. I'm still trying to figure out what to do for the rest of the ticket.
Owner

The error notifcation portion of the ticket has been released in borgmatic 1.6.6.

The error notifcation portion of the ticket has been released in borgmatic 1.6.6.
Owner

This has been implemented in borgmatic 1.7.6! To enable it, add a format option to your "all" database configuration. Then borgmatic will create individual dump files per database. See the documentation for more information: https://torsion.org/borgmatic/docs/how-to/backup-your-databases/#all-databases

This has been implemented in borgmatic 1.7.6! To enable it, add a `format` option to your "all" database configuration. Then borgmatic will create individual dump files per database. See the documentation for more information: https://torsion.org/borgmatic/docs/how-to/backup-your-databases/#all-databases
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#560
No description provided.