Backup server to local file with FirebirdSql.Data.Services.FbBackup

两盒软妹~` 提交于 2019-12-12 12:48:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!