How to perform actions after a database hook has completed but before the files gets backed up? #500

Closed
opened 2022-02-16 08:22:21 +00:00 by maxiride · 3 comments

What I'm trying to do and why

I want to perform actions on the mysqldump .sql file generated by the mysql hook.
Since mysqldump (the utility executed by the mysql hook) generates a consolidated single .sql file I want to execute the tool mysqldumpsplitter on the dump file to further fine tune the resulting backup.

The utility offers several ways to operate on a mysql dump, namely I want to split the single .sql into a file for each of its tabale, an action mysqldumpsplitter can peform very easily.

Expected behavior (if a bug)

  1. borgmatic execute the database dump
  2. a custom shell command is run
  3. files get backed up in the borg format
#### What I'm trying to do and why I want to perform actions on the mysqldump .sql file generated by the mysql hook. Since mysqldump (the utility executed by the mysql hook) generates a consolidated single .sql file I want to execute the tool [mysqldumpsplitter](https://github.com/kedarvj/mysqldumpsplitter) on the dump file to further fine tune the resulting backup. The utility offers several ways to operate on a mysql dump, namely I want to split the single .sql into a file for each of its tabale, an action mysqldumpsplitter can peform very easily. #### Expected behavior (if a bug) 1. borgmatic execute the database dump 2. a custom shell command is run 3. files get backed up in the borg format
Owner

Thanks for the question! Could you talk a little about your use case? Is it that you want to be able to restore a single table from backups without restoring the whole database? Is so, why? Do you plan to do that via borgmatic or directly with mysql via the command-line?

Unfortunately, the way that borgmatic dumps from MySQL is to stream the database dump directly from MySQL to Borg. This is for performance and disk use reasons. So there's not (currently) a good place for a third-party tool to hook in. But there might be a way to enhance borgmatic to support your use case if you tell me a little more about it.

Thanks for the question! Could you talk a little about your use case? Is it that you want to be able to restore a single table from backups without restoring the whole database? Is so, why? Do you plan to do that via borgmatic or directly with `mysql` via the command-line? Unfortunately, the way that borgmatic dumps from MySQL is to stream the database dump directly from MySQL to Borg. This is for performance and disk use reasons. So there's not (currently) a good place for a third-party tool to hook in. But there might be a way to enhance borgmatic to support your use case if you tell me a little more about it.
Author

Could you talk a little about your use case?

The use case I've faced several times is to restore a subset of tables either in the original database or in a new one spun up temporarly for investigation and debugging. Restoring the whole database for such occasions very often takes unnecessary time, load and disk space.

Do you plan to do that via borgmatic or directly with mysql via the command-line?

I strongly believe (and it's also very often reccomanded) that it's better to restore a whole datatabse at a given point in time (optionally re-running binlogs in the case of MySQL) since there is no practical way to know the exact state of the database when a crash\issue happened. Restoring a subset of tables should be a manual approach only for very specific scenarios to avoid breaking relationships between tables and the like. I don't think an automatic borgmatic pathway fits here.

So the behaviour of restoring a subset of tables I expect it to be a manual pathway where one either extract or mount a repository and like a surgeon restore what's deemed necessary. Having a backup already populated with a single .sql dump file plus the single tables would enhance and streamline such flow.


While replying I also thought of a question, how does borgmatic behave when a mysqldump is run with the --tab option? The dump contains schema and data split in different files, does borgmatic also perform a LOAD DATA statement on behalf of the user?


Closing lines

Given the sporadic need and niche use case I suppose we are better off extracting\mounting an archive whith the full database dump and manually run the mysqldump splitter tool.

> Could you talk a little about your use case? The use case I've faced several times is to restore a subset of tables either in the original database or in a new one spun up temporarly for investigation and debugging. Restoring the whole database for such occasions very often takes unnecessary time, load and disk space. > Do you plan to do that via borgmatic or directly with mysql via the command-line? I strongly believe (and it's also very often reccomanded) that it's better to restore a whole datatabse at a given point in time (optionally re-running binlogs in the case of MySQL) since there is no practical way to know the exact state of the database when a crash\issue happened. Restoring a subset of tables should be a manual approach only for very specific scenarios to avoid breaking relationships between tables and the like. I don't think an automatic borgmatic pathway fits here. So the behaviour of restoring a subset of tables I expect it to be a manual pathway where one either extract or mount a repository and like a surgeon restore what's deemed necessary. Having a backup already populated with a single .sql dump file **plus** the single tables would enhance and streamline such flow. --- While replying I also thought of a question, how does borgmatic behave when a mysqldump is run with the [--tab option](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html#option_mysqldump_tab)? The dump contains schema and data split in different files, does borgmatic also perform a `LOAD DATA` statement on behalf of the user? --- Closing lines Given the sporadic need and niche use case I suppose we are better off extracting\mounting an archive whith the full database dump and manually run the mysqldump splitter tool.
Owner

While replying I also thought of a question, how does borgmatic behave when a mysqldump is run with the --tab option? The dump contains schema and data split in different files, does borgmatic also perform a LOAD DATA statement on behalf of the user?

I wasn't aware of this option, but my guess is that at least currently, it wouldn't work. That's because borgmatic expects mysqldump to stream a single dump file to standard output. However, you are welcome to try this option as an experiment, selecting a destination directory that you've configured to be backed up as part of borgmatic's source_directories. That would probably mean you couldn't restore those tab-separate files with borgmatic restore, but you might be able to restore them manually.

Given the sporadic need and niche use case I suppose we are better off extracting\mounting an archive whith the full database dump and manually run the mysqldump splitter tool.

Sounds good. I'll close this for now, but feel free to add any other thoughts/feedback here.

> While replying I also thought of a question, how does borgmatic behave when a mysqldump is run with the --tab option? The dump contains schema and data split in different files, does borgmatic also perform a LOAD DATA statement on behalf of the user? I wasn't aware of this option, but my guess is that at least currently, it wouldn't work. That's because borgmatic expects `mysqldump` to stream a single dump file to standard output. However, you are welcome to try this option as an experiment, selecting a destination directory that you've configured to be backed up as part of borgmatic's `source_directories`. That would probably mean you couldn't restore those tab-separate files with `borgmatic restore`, but you might be able to restore them manually. > Given the sporadic need and niche use case I suppose we are better off extracting\mounting an archive whith the full database dump and manually run the mysqldump splitter tool. Sounds good. I'll close this for now, but feel free to add any other thoughts/feedback here.
witten added the
question / support
label 2022-03-05 22:32:46 +00:00
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#500
No description provided.