Mysql backup fails due to closed pipe when exclude_nodump is set #720
Labels
No Label
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No Milestone
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: borgmatic-collective/borgmatic#720
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
I am trying to use borgmatic to back up my mysql databases
Steps to reproduce (if a bug)
Set up a mysql database and a borgmatic config file.
Try to run a backup of the database
Actual behavior (if a bug)
The mysqldump itself fails with an EPIPE error.
I have run borgmatic under
strace
as well, and I was able to find thatborg [...] --dry-run --list
opens and closes the pipe file, which results in the mysqldump failing before the actual backup can be started.Relevant strace snippets, with comments
Expected behavior (if a bug)
Other notes / implementation ideas
This error can be avoided by either omitting the
--dry-run --list
invocation of borg, or only starting the mysqldump after the dry-run has run.When starting the mysqldump after the dry-run has run, I think that borg may get stuck while trying to read from the pipe. To solve that problem, you can write some dummy content to the pipe before starting borg in dry-run mode. (e.g. simply
echo "" > /root/.borgmatic/mysql_databases/localhost/all
i the same way that mysqldump is started now)Environment
borgmatic version: 1.7.7
borgmatic installation method: Debian package
Borg version: borg 1.2.4
Python version: Python 3.11.2
Database version (if applicable): mysql Ver 15.1 Distrib 10.11.3-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
operating system and version: Debian GNU/Linux 12
Thanks for filing the detailed ticket + annotated strace logs! I've tried to repro this locally, but thus far I haven't had any luck even though I'm using the same version of borgmatic and Borg and MariaDB. (Although my version of
mysqldump
is 10.11.2.)Looking at the comparable
strace -f
on my own system though, I'm only seeing themysqldump
opening the named pipe. The Borg dry run appears to be stat-ing it, but that's it. So given that we're using the exact same version of Borg, do you have any ideas as to what might be causing this difference in behavior? Here's my Borg dry run invocation from strace, which looks very similar to yours minus some of the exclude flags:If it comes to it, I could try spinning up a Debian VM just to attempt to get a better repro.
Both borg and borgmatic are the version from the debian repositories.
I just tried running the backup without the exclude flags, they are not important here, but were included from a global configuration.
It looks like borg does take a different approach and does not open any files now, it only opens and reads directories now, it doesn't open the pipe itself.
I found the cause of the different path in borg.
When
exclude_nodump: true
, borg tries to read the flags.https://github.com/borgbackup/borg/blob/1.2.4/src/borg/archiver.py#L776-L781
For the linux platform, this results in the file being opened, an ioctl being executed and then the file being closed.
https://github.com/borgbackup/borg/blob/1.2.4/src/borg/platform/linux.pyx#L156
The same behavior is still there in the latest version.
At this point, I'm not sure if this should be considered a bug in borg or in borgmatic.
With the same exclude options, borg itself works fine to run the backup, as long as you don't use
--dry-run
first without restarting the mysqldump on the other side of the pipe.Amazing detective work!
So am I to take it that without
exclude_nodump
, this borgmatic MySQL error stops happening and the action succeeds?I think it's fair to call it an unfortunate interaction between the two. It wouldn't be the first—the whole purpose of the dry run to begin with is to find special files so that they can be auto-excluded to prevent Borg from hanging due to an interaction with borgmatic's named pipe!
In any case, I think this is probably something borgmatic can work around. Omitting the
--exclude-nodump
flag on the dry run (only) should be easy enough, and it sounds like that should sidestep the issue in this ticket.Mysql backup fails due to closed pipeto Mysql backup fails due to closed pipe when exclude_nodump is setI've got a local repro now and confirmed that with the
exclude_nodump
option, the MySQL error happens. And also that withoutexclude_nodump
, the error goes away. So I went ahead and omitted--exclude-nodump
inside the dry run code, and now things appear to work even when the option is set in borgmatic's configuration file. This fix will be part of the next release.. Thanks again for all your work here!I found the same behaviour with PostgreSQL,
pg_dumpall
would fail with code 141 whenexclude_nodump: true
is set, but outside of dry runs. Removingexclude_nodump: true
fixes the issue. Is it possible PostgreSQL databases are treated differently compared to MySQL for dumps?@jchristgit Are you running main or a released version of borgmatic? The fix in this ticket (which should apply to PostgreSQL too) hasn't been released yet; it'll go out in 1.8.0.
Released in borgmatic 1.8.0!
Ah sorry, looks like my previous reply per mail didn't arrive - per your suggestion, I should have tested with main first, I cannot reproduce the issue there even without dry run... Thank you so much!