sql-serverbackuprestoredatabase-restore

Is there a way to keep on restoring SQL database backups periodically, and meanwhile access the database from another application?


I'm periodically getting backups of an SQL database which I would like to restore in my machine. I'm able to do that with RESTORE fullDB WITH NORECOVERY; RESTORE differentialDB WITH RECOVERY;

However, I need to access the restored database in between, as the interval in which I'm getting the backups can be a few hours.

I tried restoring full backup WITH RECOVERY, but in that case I'm getting exception while restoring differential backup.

NB: It's not just one differential backup, it's real time backups taken every few hours. I'm using C# for executing the operations.

Any help is appreciated to solve the issue. Also, let me know if I'm barking at the wrong tree. Instead of sending SQL database backups from client as .bak files, should I opt any other way to send the data?


Solution

  • Take a look at the STANDBY option for the RESTORE statement. From the docs:

    Specifies a standby file that allows the recovery effects to be undone.

    NB - differential backups are based on the last full backup taken. So let's say that you take full backups on Sunday, differential backups every other day of the week and you're restoring every day.

    That said, you mentioned that you're on SQL Express. The database size limit is 10 Gb. At that size, how long does the restore of the full backup take? Is it worth your time? And even there, it's really "how much time are you saving the robot?" because you've already (presumably) automated the restore.