300 | | /* So we don't have to specify the password on the command line, use |
301 | | --defaults-extra-file to specify a temporary file with a [client] and |
302 | | [mysqldump] section that provides the password. This will fail if the |
303 | | user's ~/.my.cnf (which is read after the --defaults-extra-file) |
304 | | specifies a different password that's incorrect for dbUserName */ |
305 | | QString tempExtraConfFile = QDeepCopy<QString>( |
| 318 | // Create a temporary file containing the database information |
| 319 | QString tempDatabaseConfFile = QDeepCopy<QString>( |
312 | | .arg(tempExtraConfFile.ascii())); |
313 | | VERBOSE(VB_IMPORTANT, LOC_ERR + QString("Attempting backup, anyway. " |
314 | | "If the backup fails, please add the %1 user's database " |
315 | | "password to your MySQL option file.") |
316 | | .arg(dbParams.dbUserName)); |
| 326 | .arg(tempDatabaseConfFile.ascii())); |
| 327 | VERBOSE(VB_IMPORTANT, LOC_ERR + "Attempting backup, anyway."); |
| 328 | tempDatabaseConfFile = ""; |
320 | | chmod(tempExtraConfFile.ascii(), S_IRUSR); |
321 | | fprintf(fp, QString("[client]\npassword=%1\n" |
322 | | "[mysqldump]\npassword=%2\n") |
323 | | .arg(dbParams.dbPassword).arg(dbParams.dbPassword)); |
| 332 | chmod(tempDatabaseConfFile.ascii(), S_IRUSR); |
| 333 | fprintf(fp, QString("DBHostName=%1\n" |
| 334 | "DBPort=%2\n") |
| 335 | .arg(dbParams.dbHostName).arg(dbParams.dbPort)); |
| 336 | fprintf(fp, QString("DBUserName=%1\n" |
| 337 | "DBPassword=%2\n") |
| 338 | .arg(dbParams.dbUserName).arg(dbParams.dbPassword)); |
| 339 | fprintf(fp, QString("DBName=%1\n" |
| 340 | "DBSchemaVer=%2\n") |
| 341 | .arg(dbParams.dbName).arg(dbSchemaVer)); |
| 342 | fprintf(fp, QString("DBBackupDirectory=%1\n" |
| 343 | "DBBackupFilename=%2\n") |
| 344 | .arg(backupDirectory) |
| 345 | .arg(backupFilename)); |
329 | | QString command; |
330 | | QString compressCommand(""); |
331 | | QString extension = ".sql"; |
332 | | if (QFile::exists("/bin/gzip")) |
333 | | compressCommand = "/bin/gzip"; |
334 | | else if (QFile::exists("/usr/bin/gzip")) |
335 | | compressCommand = "/usr/bin/gzip"; |
336 | | else |
337 | | VERBOSE(VB_IMPORTANT, "Neither /bin/gzip nor /usr/bin/gzip exist. " |
338 | | "The database backup will be uncompressed."); |
339 | | |
340 | | QString backupPathname = backupDirectory + "/" + |
341 | | CreateBackupFilename(dbParams.dbName + "-" + |
342 | | dbSchemaVer, extension); |
343 | | command = QString("mysqldump --defaults-extra-file='%1' --host='%2'" |
344 | | " --user='%3' --add-drop-table --add-locks" |
345 | | " --allow-keywords --complete-insert" |
346 | | " --extended-insert --lock-tables --no-create-db --quick" |
347 | | " '%4' > '%5' 2>/dev/null") |
348 | | .arg(tempExtraConfFile).arg(dbParams.dbHostName) |
349 | | .arg(dbParams.dbUserName).arg(dbParams.dbName) |
350 | | .arg(backupPathname); |
351 | | VERBOSE(VB_FILE, QString("Backing up database with command: %1") |
352 | | .arg(command.ascii())); |
353 | | VERBOSE(VB_IMPORTANT, QString("Backing up database to file: %1") |
354 | | .arg(backupPathname.ascii())); |
| 351 | QString command = backupScript + " " + tempDatabaseConfFile; |
| 352 | VERBOSE(VB_IMPORTANT, QString("Backing up database with script: %1") |
| 353 | .arg(backupScript)); |
370 | | VERBOSE(VB_IMPORTANT, "Compressing database backup file."); |
371 | | compressCommand += " " + backupPathname; |
372 | | status = system(compressCommand.ascii()); |
373 | | |
374 | | if (status) |
375 | | { |
376 | | VERBOSE(VB_IMPORTANT, |
377 | | "Compression failed, backup file will remain uncompressed."); |
378 | | } |
379 | | else |
380 | | { |
381 | | backupPathname += ".gz"; |
382 | | |
383 | | VERBOSE(VB_IMPORTANT, QString("Database Backup filename: %1") |
384 | | .arg(backupPathname.ascii())); |
385 | | } |
| 373 | // If no file begins with the suggested filename, don't show the backup |
| 374 | // filename in the GUI message |
| 375 | filename = ""; |
| 376 | VERBOSE(VB_FILE, LOC_ERR + QString("No files beginning with the " |
| 377 | "suggested database backup filename (%1) were found in %2.") |
| 378 | .arg(backupFilename).arg(backupDirectory)); |
387 | | |
388 | | VERBOSE(VB_IMPORTANT, "Database Backup complete."); |
389 | | |
390 | | filename = backupPathname; |
| 380 | else |
| 381 | { |
| 382 | filename = dir.path() + "/" + dir[0];; |
| 383 | if (numfiles > 1) |
| 384 | VERBOSE(VB_FILE, LOC_ERR + QString("Multiple files beginning with " |
| 385 | "the suggested database backup filename (%1) were found " |
| 386 | "in %2. Assuming the first is the backup.") |
| 387 | .arg(backupFilename).arg(backupDirectory)); |
| 388 | } |
| 389 | if (!filename.isEmpty()) |
| 390 | VERBOSE(VB_IMPORTANT, QString("Backed up database to file: %1") |
| 391 | .arg(filename)); |