'gbak gives system directive access failed on Ubuntu when running from net core application
Basically, I want to run a gbak restore (Firebird 3) from my ASP.NET Core application on Ubuntu.
Here is my code:
string output = "";
using (Process pProcess = new System.Diagnostics.Process())
{
pProcess.StartInfo.FileName = "gbak";
//pProcess.StartInfo.UseShellExecute = true;
pProcess.StartInfo.RedirectStandardError = true;
pProcess.StartInfo.Arguments = "-c /home/database/backup.gbk /home/database/tempdb.fdb -user SYSDBA -pass masterkey -r";
pProcess.StartInfo.CreateNoWindow = true;
pProcess.Start();
output = pProcess.StandardError.ReadToEnd();
pProcess.WaitForExit();
}
return output;
This gives me an error:
gbak: ERROR:operating system directive access failed
gbak: ERROR: Not a directory
gbak: ERROR:failed to create database /home/database/tempdb.fdb
gbak:Exiting before completion due to errors
If I execute the same command directly from the terminal, it works just fine:
gbak -c /home/database/backup.gbk /home/database/tempdb.fdb -user SYSDBA -pass masterkey -r
Also I have tried with and without UseShellExecute and got the same result.
Any idea on what's going on?
Solution 1:[1]
You are getting this message because you are trying to use Firebird engine in embedded mode without proper UID/GID set for the process.
You'd better to use Services API via remote connection. Look at this example: https://github.com/FirebirdSQL/NETProvider/blob/master/docs/services-backup.md
Solution 2:[2]
I have managed to solve the problem. As mentioned before, my initial code was using the embedded version of Firebird.
Here is the correct way in my opinion to do that, with a bonus using the service_mgr which is much much faster:
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.CreateNoWindow = true;
pProcess.StartInfo.FileName = "gbak";
pProcess.StartInfo.Arguments = "-se localhost:service_mgr -c /home/database/backup.gbk /home/database/tempdb.fdb -user SYSDBA -pass masterkey";
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user13964273 |
| Solution 2 | Mark Rotteveel |
