Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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...

like image 274
neggenbe Avatar asked Nov 02 '25 07:11

neggenbe


1 Answers

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();
}
like image 102
Mark Rotteveel Avatar answered Nov 03 '25 22:11

Mark Rotteveel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!