As part of the build process, i want to take a snapshot of a number of
tables from a mysql database. In order to do this, I am using a Process task
to run mysqldump:
task exportProductbaseData << { task ->
new File(outdir).mkdirs()
Process proc =
["/usr/bin/mysqldump","-uusername","-ppassword","-hdev-db-01","dbname","table1","table2","table3","table4"].execute()
proc.consumeProcessErrorStream(System.err)
proc.consumeProcessOutputStream(new FileWriter("$outdir/$dbFname"))
if (proc.waitFor() != 0) {
throw new RuntimeException('exec failed')
}
}
The mysqldump file terminates early, ending in the middle of a data entry
e.g.
<insert statement> <some rows>, (207, "some_key", "some very long value
gets cut off
I'm guessing this is because of the output buffer off the FileWriter that I
am doing incorrect. 2 questions:
1. is there a better way to approach the problem?
2. how would i fix this problem so that mysqldump output is written to the
file correctly?