Home Forums SQL Server 2008 SQL Server Newbies automate estore database into database with a different name RE: automate estore database into database with a different name

  • This is what I do...

    on prod server create this as a job and schedule:

    BACKUP DATABASE DB1PROD TO DISK = '\\PQASERVER\H$\backups\DB1PROD_db.BAK'

    On test server schedule this as a job some time after the restore completes:

    RESTORE DATABASE [DB1PQA] FROM DISK = N'H:\backups\DB1PROD_db.BAK' WITH FILE = 1, NOUNLOAD, REPLACE

    GO

    use DB2PQA

    alter database DB1PQA set recovery simple

    then reset users for the non-prod db

    then another step, Operating system of this to delete the backup file

    del H:\backups\TMXPROD_db.bak

    For your environment for whatever steps you use normally to restore the db just hit the script button which will script out the DDL required for each step. Then you can put that into steps in the job. Put the different tasks in different steps so if the job fails you can easily see what failed, fix it and restart it from that point forward. I have a handful of restores setup as jobs so if someone wants the db refreshed in a nonprod environment all the steps are in the jobs so I don't accidentally miss something AND it takes only a few seconds to refresh the db.