I am using SQL Server 2022 Express on Ubuntu Server 22.04, and PHP 8.3.
I am trying to backup a database, the instruction is: BACKUP DATABASE WEBDEV TO DISK = ‘/temp/WEBDEV.bak’, and when I execute it from Management Studio, it creates the file correctly, but when I execute it from PHP it does not show any error, but the file is not created. I already make the /temp/ directory with 777 permission, and the result is the same, It does not create the backup file and it does not show any error.
My code is this:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$conn = new PDO("sqlsrv:server=localhost;database=WEBDEV;TrustServerCertificate=true", "bkuser", "thepassword");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "BACKUP DATABASE WEBDEV TO DISK = '/temp/WEBDEV.bak'";
try {
$conn->exec($sql);
echo "Backup completed successfully";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
It does not show any error message, it shows the “Backup completed successfully” message.
The mssql error log shows this: BACKUP failed to complete the command BACKUP DATABASE WEBDEV. Check the backup application log for detailed messages.
But there is no backup log anywhere.
I checked access for the mssql user to the directory, and as I said, from Management Studio it creates correctly. That is why I tried with 777 permissions to be sure about the access to the directory.
Any of you had this issue? any ideas?