Skip to content

Commit

Permalink
cron/mysql-dump: add flexibility
Browse files Browse the repository at this point in the history
add --extended-insert flag to pass through to mysqldump to enable
extended-insert (one big INSERT statement instead of one per row.)
Set to 1 to enable.  These can be much faster for imports.

add --override-backupdir flag to override the output directory
that is specified in the config.
  • Loading branch information
rspier authored and andk committed Apr 25, 2024
1 parent 14e0a59 commit b54e8bd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cron/mysql-dump.pl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
die "where is BZIP" unless -x $BZIP;
use File::Path ();
use File::Basename ();
use Getopt::Long qw(GetOptions);

my $extended_insert = 0;
my $override_backupdir;
GetOptions(
"extended-insert=i" => \$extended_insert,
"override-backupdir=s" => \$override_backupdir
) or die("Error in command line arguments\n");

my $Struct = [
{backupdir => "$PAUSE::Config->{FTPPUB}/PAUSE-data",
Expand All @@ -42,7 +50,7 @@
},
];
for my $struct (@$Struct) {
my $backup_dir = $struct->{backupdir};
my $backup_dir = $override_backupdir || $struct->{backupdir};
File::Path::mkpath $backup_dir;
my($dbi,$dbengine,$db) = split /:/, $PAUSE::Config->{$struct->{cfg_dsn}};
die "Script would not work for $dbengine" unless $dbengine =~ /mysql/i;
Expand All @@ -55,7 +63,7 @@
if ($struct->{master}) {
$master_data = " --master-data";
}
system "mysqldump$master_data --lock-tables --add-drop-table --user='$user' --password='$password' '--extended-insert=0' '$db' > $backup_dir/.${db}dump.current";
system "mysqldump$master_data --lock-tables --add-drop-table --user='$user' --password='$password' '--extended-insert=$extended_insert' '$db' > $backup_dir/.${db}dump.current";
rename "$backup_dir/.${db}dump.current", "$backup_dir/${db}dump.current";
unlink "$backup_dir/${db}dump.current.bz2";
system "$BZIP -9 --keep --small $backup_dir/${db}dump.current";
Expand Down

0 comments on commit b54e8bd

Please sign in to comment.