4

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

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
neggenbe
  • 1,697
  • 2
  • 24
  • 62

1 Answers1

6

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();
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • AWESOME dude, THANKS a million, that's precisely it. You ROCK! – neggenbe Dec 14 '18 at 15:20
  • As a side question - I get an "out of memory" exception (the DB is actually quite large) - anything I can do about it??? (DB is about 200Mb, so not actually unmanageable...) – neggenbe Dec 14 '18 at 15:22
  • 1
    @neggenbe Are you using a memory stream to create the backup instead of a file stream? – Mark Rotteveel Dec 14 '18 at 15:28
  • you're my today's absolute hero!!!!!! Thanks Mark!!!!! An all that within 30 minutes! Awesome, made my day! – neggenbe Dec 14 '18 at 15:33