问题
I'm trying to use following code to backup a database located on a remote server on which I do NOT have write permission :
FbBackup backupSvc = new FbBackup();
backupSvc.ConnectionString = ConnectionStr; // on remote server
backupSvc.BackupFiles.Add(new FbBackupFile(destFile)); // local file
backupSvc.Verbose = true;
backupSvc.Options = FbBackupFlags.IgnoreLimbo;
backupSvc.ServiceOutput += ServiceOutput;
backupSvc.Execute();
This works just perfectly fine if the DB is on localhost
or if I can write to the server folder. The problem is when I need to save the file to the local machine (since I do NOT have permissions on the server). Weirdly enough, the service output shows the usual output - just that at the end, the local file is NOT created...!
I read here about using gbak
, but I ran into many other problems using that. I am pretty sure there is a missing parameter or any other weird trick I'm missing...
回答1:
The FbBackup
class only implements the normal gbak operation where a client can trigger a backup, but the backup is written on the server (using the access rights of the Firebird server process).
If you want the backup to be created on the client, you need to use FirebirdSql.Data.Services.FbStreamingBackup
instead.
See also https://www.tabsoverspaces.com/233462-ado-net-provider-4-2-0-0-for-firebird-is-ready
A minimal example:
static void Main(string[] args)
{
var connectionString = new FbConnectionStringBuilder
{
Database = "employee",
DataSource = "sagittarius",
ServerType = FbServerType.Default,
UserID = "sysdba",
Password = "masterkey",
}.ToString();
using (var output = File.Create(@"D:\Temp\remotebackup.fbk"))
{
var backup = new FbStreamingBackup();
backup.ConnectionString = connectionString;
backup.OutputStream = output;
backup.Execute();
}
Console.ReadLine();
}
来源:https://stackoverflow.com/questions/53782117/backup-server-to-local-file-with-firebirdsql-data-services-fbbackup