Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to automate a backup on prod and a restore on test? Expand / Collapse
Author
Message
Posted Thursday, September 3, 2009 8:14 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Today @ 7:16 AM
Points: 330, Visits: 371
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



Post #782209
Posted Thursday, September 3, 2009 8:26 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 12:34 PM
Points: 31,181, Visits: 15,626
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.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #782223
Posted Thursday, September 3, 2009 11:30 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, June 13, 2014 10:40 AM
Points: 368, Visits: 543
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
SQLServerGeeks.com/blogs/sarab
www.Sarabpreet.com
Twitter: @Sarab_SQLGeek
Post #782417
Posted Thursday, September 3, 2009 12:12 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Today @ 7:16 AM
Points: 330, Visits: 371
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



Post #782465
Posted Thursday, September 3, 2009 12:55 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 12:34 PM
Points: 31,181, Visits: 15,626
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.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #782495
Posted Thursday, September 3, 2009 2:28 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Today @ 7:16 AM
Points: 330, Visits: 371
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



Post #782561
Posted Friday, September 4, 2009 1:59 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, June 13, 2014 10:40 AM
Points: 368, Visits: 543
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





Regards,
Sarabpreet Singh
SQLServerGeeks.com/blogs/sarab
www.Sarabpreet.com
Twitter: @Sarab_SQLGeek
Post #782762
Posted Wednesday, April 11, 2012 1:54 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, May 4, 2012 3:41 PM
Points: 3, Visits: 48
Good stuff people. Thanks!
Post #1281940
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse