How to automate a backup on prod and a restore on test?

  • We are running SQL Server 2000 (SP4) on Windows Server 2003.

    I am looking for a simple, easy to implement method that would allow me to automatically restore the production sql server backups to the test databases. Currently, I back up the sql server databases on the production server and then xcopy the backups (just for storage on another box) to the test server. Note the backup file name contains the date and time stamp (pubs_backup_200909020421.BAK) so the restore script would have to reference this exact name in a scheduled process. (I currently use the SQL Maintenance Plans on the Production Server to create my sql server backups with the date time stamp as part of the backup file name.)

    I would think I would have to use a script to backup the database on the production server, xcopy the backup to the test server, and then use a script to restore the database on the test server.

    1) On Production Server:

    USE pubs

    BACKUP DATABASE pubs TO

    DISK= 'd:\sqlbackups\pubs_backup_200902031724.bak';

    GO

    RESTORE VERIFYONLY FROM DISK = 'd:\sqlbackups\pubs_backup_200902031724.bak';

    2) On Test Server;

    Scheduled XCopy Process which copies the backup file from production server to test server.

    3) On Test Server:

    RESTORE DATABASE pubs

    FROM DISK = 'd:\sqlbackups\pubs_backup_200902031724.bak';

    Please provide advice especially with how to handle the date time stamp placed on the backup file name by the SQL Maintenance Plans.

    Or, should I backup each daily file to a name like: 'd:\sqlbackups\pubs_backup_sunday.bak'

    And then have a scheduled restore script to restore this particular daily backup file name.

    Lastly, is there a way to spool the output of the backup, verify and restore commands to a text file?

    Thanks, Kevin

  • I'd keep things the way they are. Then use VBScript (FileSystemObject) or Powershell to find the latest backup (not hard to do, loop files, find last one) and copy that to the test machine with a set name (LatestProdBackup.bak).

    Set a restore script to restore this.

    Use separate names on production, same name on test, some tweaking to do in the restore, remove users, sync logins, etc., but not that hard.

  • Hi,

    I've done this in my prod. and reporting. Not so difficult, just follow these steps (modify as per your needs)

    we take diff backup every night on our prod. so that we can prepare the reporting.

    1. Disable the log backup on prod.

    2. Take the Backup of the DB with a preset name in to a folder lets say : latest_backup

    3. initiate the process of copying the backup to destination server after intigrity checks (you'll face no problem because you've taken the backup with a pre-defined name which will remain the same.)

    4. After copy finish rename the backup file on prod. and move it to another folder so that every time you'll have only one backup in Latest_backup folder (You can also skip to move file to another folder I do this for some specific requirement)

    5. remove all user sessions on destination DB (this can be easily achived by a constomized sp by which i use to kill all user sessions on my reporting server except some specific accounts)

    6. REstore the DB using a predefined query since the name of the backup file is still pre-defined

    7. rename the backup file at the destination server and again you've the option to move it to another folder.

    Regards,
    Sarabpreet Singh 😎
    Sarabpreet.com
    SQLChamp.com
    Twitter: @Sarab_SQLGeek

  • Sarabpreet,

    Thanks for your response. I have two questions; what do you mean when you say:

    1. Disable the log backup on prod.

    I am taking a nightly full database backup and log file backup even though we are not using the log backups to retore. So, basically, I have a full database backup.

    Also, what do you mean when you say to restore the database using a query.

    6. Restore the DB using a predefined query since the name of the backup file is still pre-defined.

    I normally use a Restore Command.

    Thanks, Kevin

  • You should not need to disable the log backup.

    I think for #2, he means a RESTORE command as the query. It's not a query per se, but a batch command.

  • Just curious, when you say to 'disable a log backup', do you mean to stop the SQL Maintenance Plan from creating the log backup?

    Kevin

  • kevinsql7 (9/3/2009)


    Sarabpreet,

    Thanks for your response. I have two questions; what do you mean when you say:

    1. Disable the log backup on prod.

    My DB size is around 800 GBs and our Diff. backup takes 2-3hrs time to complete that too with the help of Red-Gate, now during this time our log backup has to wait and just to avoid this i disable the job. (I think if any backup is running on a DB you can't run any other backup on the same DB)

    I am taking a nightly full database backup and log file backup even though we are not using the log backups to retore. So, basically, I have a full database backup.

    So in your case you don't have to worry about this.

    Also, what do you mean when you say to restore the database using a query.

    6. Restore the DB using a predefined query since the name of the backup file is still pre-defined.

    Steve is right, i was refering to RESTORE Command....My mistake:rolleyes:

    Regards,
    Sarabpreet Singh 😎
    Sarabpreet.com
    SQLChamp.com
    Twitter: @Sarab_SQLGeek

  • Good stuff people. Thanks!

Viewing 8 posts - 1 through 7 (of 7 total)

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