use diagnostics;
use strict;
+use File::Temp;
require "globals.pl";
require "defparams.pl";
my $verbose = 0;
my $syncall = 0;
my $shutdown = 0;
-my $tempdir = "data";
+my $tempdir = File::Spec->tmpdir;
my $force = 0;
my $shutdown_msg = "Bugzilla is temporarily disabled while the database is backed up. Try again in a few minutes.";
}
Verbose("Locking entire database");
SendSQL($query);
- my $tempfile = "$tempdir/tmpsyncshadow.$$";
+ my ($tmpfh, $tempfile) = File::Temp::tempfile("syncshadowdb.XXXXX",
+ DIR => $tempdir, UNLINK => 1);
Verbose("Dumping database to a temp file ($tempfile).");
my @ARGS = ("-u", $::db_user);
if ($::db_pass) { push @ARGS, "-p$::db_pass" }
push @ARGS, "-l", "-e", $::db_name, @tables;
open SAVEOUT, ">&STDOUT"; # stash the original output stream
- open STDOUT, ">$tempfile"; # redirect to file
+ open STDOUT, ">&", $tmpfh; # redirect to temp filehandle
select STDOUT; $| = 1; # disable buffering
system("$::mysqlpath/mysqldump", @ARGS);
open STDOUT, ">&SAVEOUT"; # redirect back to original stream
if ($verbose) {
$extra .= " -v";
}
- open(MYSQL, "cat $tempfile | $::mysqlpath/mysql $extra " .
+ open (MYSQL, "/bin/cat $tempfile | $::mysqlpath/mysql $extra " .
Param("shadowdb") . "|") || die "Couldn't do db copy";
my $count = 0;
while (<MYSQL>) {
}
}
close(MYSQL);
- unlink($tempfile);
+ close($tmpfh);
Verbose("");