0

I've found out how to perform a streamed backup from this post.

Now, I'm facing the reverse problem - I want to perform a restore from a backup file. It is quite easy when I have a local backup file - the problem is, how to check if the remote backup file exists?

Example: my connection string is as follows : datasource=192.168.1.123;database=D:/data/MyDatabase.FDB;...

And I want to check if the file \\192.168.1.123/D:/data/MyDatabase.fbk exists before running the restore service. Note that File.Exists(@"\\192.168.1.123/D:/data/MyDatabase.fbk") returns false. I don't really know how to make sure the file exists before running the restore. Any idea?

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

1 Answers1

2

Just perform the restore and Firebird will return an error if the backup file does not exist. If the backup file does not exist, Firebird will return error:

cannot open backup file <backup-path>
Exiting before completion due to errors

Alternatively, you need to have some form of remote access to the other system to check its filesystem. Firebird itself doesn't offer such an option (apart from just trying the restore and see if it works).

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • it kind of does: external tables :-D Granted, security should be set proper way for it, etc. – Arioch 'The Jan 17 '19 at 17:57
  • @Arioch'The That would be an extremely dirty hack and you'd need to apply very insecure config to Firebird or do stupid things like combining external table location with your backups, neither is appropriate to do at all. You could create a UDF or UDR to do this, which would still be technically an unsafe practice to allow inspection of your file system like that, but at least it is not a dirty hack. – Mark Rotteveel Jan 17 '19 at 18:07
  • I did not say this would be a solution for this question (it obviously would not), but the claim that Firebird doesn't have an option to access filesystem is incorrect nonetheless. It does have, and I named it. That option can not help this question, sure, but it does exist. – Arioch 'The Jan 18 '19 at 09:18
  • @MarkRotteveel That's what I did - put the restore in a `try-catch` block... Would be nice to have an explicit test method though... – neggenbe Jan 18 '19 at 13:22
  • @neggenbe Even if such a method existed, you would still need to handle non-existence because of Time-Of-Check-to-Time-Of-Use (TOC/TOU) errors (ie the backup file is deleted between the check for existence and its use by the restore). Also, existence of a file does not necessary mean the process is allowed to open the file, etc. – Mark Rotteveel Jan 18 '19 at 14:52
  • @MarkRotteveel You are right, didn't think about that. Then, it would make sense to implement the API as a web- or REST service returning error codes - that would allow to handle things more properly on the server. Thanks for the help though, much appreciated ! – neggenbe Jan 21 '19 at 07:19