Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


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


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

Author
Message
HookSqlDba7
HookSqlDba7
Old Hand
Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)

Group: General Forum Members
Points: 384 Visits: 520
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



Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36150 Visits: 18751
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
My Blog: www.voiceofthedba.com
Sarab_SQLGeek
Sarab_SQLGeek
Old Hand
Old Hand (372 reputation)Old Hand (372 reputation)Old Hand (372 reputation)Old Hand (372 reputation)Old Hand (372 reputation)Old Hand (372 reputation)Old Hand (372 reputation)Old Hand (372 reputation)

Group: General Forum Members
Points: 372 Visits: 558
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 Cool
Sarabpreet.com
SQLChamp.com
Twitter: @Sarab_SQLGeek
HookSqlDba7
HookSqlDba7
Old Hand
Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)

Group: General Forum Members
Points: 384 Visits: 520
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



Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36150 Visits: 18751
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
My Blog: www.voiceofthedba.com
HookSqlDba7
HookSqlDba7
Old Hand
Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)

Group: General Forum Members
Points: 384 Visits: 520
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



Sarab_SQLGeek
Sarab_SQLGeek
Old Hand
Old Hand (372 reputation)Old Hand (372 reputation)Old Hand (372 reputation)Old Hand (372 reputation)Old Hand (372 reputation)Old Hand (372 reputation)Old Hand (372 reputation)Old Hand (372 reputation)

Group: General Forum Members
Points: 372 Visits: 558
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 mistakeRolleyes

Regards,
Sarabpreet Singh Cool
Sarabpreet.com
SQLChamp.com
Twitter: @Sarab_SQLGeek
saly1
saly1
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 48
Good stuff people. Thanks!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search