Backing up and restoring MSDE from application

  • I am writing a vb.net application using MSDE. My user is asking me to provide him a backup and restore facility from inside the application. I had a look at this KB article http://support.microsoft.com/default.aspx?scid=kb;EN-US;241397. It looks fine, I was just wondering if somebody put it into practice. What I see is that I'll have to pass down parameters such as the dbname and allow my user to specify the destination for the backup.

    Also I am wondering about the restore part of it. If it's necessary to detach the db, etc.

    jean-luc

    http://www.corobori.com


    Jean-Luc
    www.corobori.com

  • I assume that this user will be the only one using the database.  When he wants to restore noone else can be using the databases.  So rather than connect to the user database the application should connect to master.  If another using connects to the database the restore will not work.  Detach has nothing to do with restore.

     

     

    Francis

  • I think you probably want to control this better and use a table of some sort in your db to store the backup locations and file names. Then let the user pick from this list to do the restore.

    Keep in mind that when you restore the user must be "out of the database", so they need another db in which to hold their context, like master.

  • Here are two SQL statements, the first list all saved backups and dates for a database.  The seconds displaces the latest backup file name.

     

    DECLARE @db  as sysname

    SET @db = 'databasename'

    select physical_device_name ,  backup_start_date

     from  msdb.dbo.backupset a join msdb.dbo.backupmediaset b on a.media_set_id = b.media_set_id

          join msdb.dbo.backupmediafamily c on a.media_set_id = c.media_set_id

           where type='D' AND database_name = @db

    select physical_device_name ,  backup_start_date, *

     from  msdb.dbo.backupset a join msdb.dbo.backupmediaset b on a.media_set_id = b.media_set_id

          join msdb.dbo.backupmediafamily c on a.media_set_id = c.media_set_id

           where type='D' and backup_start_date =

            (select top 1 backup_start_date from msdb.dbo.backupset

                 where database_name = @db and type = 'D'

                  order by backup_start_date desc) 

    Francis

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply