I created a script in PHP / PDO that executes a line of SQL to make a file backup of various databases. The list of database names and the datestamp with which to select the folder into which to place the file are passed as HTTP REQUEST array elements. The script works, but for some reason SQL Server is deleting the file as soon as the script finishes running. With Explorer open, I can watch the folder and file get created correctly, but the file disappears upon completion. Here's the
$dbh = getPDOConnection();
$sql = "BACKUP DATABASE :database TO DISK = :path";
$sth = $dbh->prepare($sql);
$dt = $_REQUEST["dtStamp"];
$uncPath = "\\\\[unc server]\\c$\MSSQL\\Backup\\backups_$dt";
if (!file_exists($uncPath)) {
mkdir($uncPath, null, true);
}
$responses = [];
foreach(explode(",", $_REQUEST["databases"]) AS $d=>$database) {
$sqlPath = "c:\\MSSQL\\Backup\\backups_$dt\\$database.bak";
$sth->bindValue(":database", $database);
$sth->bindValue(":path", $sqlPath);
$sth->execute();
$responses[] = $sth->fetch(PDO::FETCH_ASSOC);
}
Can anyone point me to what I'm missing? I can't seem to find any documentation from Microsoft that indicates why this behavior would occur.