SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Automate Your Backup and Restore Tasks


Automate Your Backup and Restore Tasks

Author
Message
2Tall
2Tall
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6746 Visits: 1218
Comments posted to this topic are about the item Automate Your Backup and Restore Tasks

-------------------------------------------------------------------------------------
A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."

Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '

Tommy Cooper

ronclauw
ronclauw
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 182
Hi,


To drop a database (in this case: Develop) use this script:

if exists (select name from master.sys.databases where name = 'Develop')
begin
alter database Develop
set restricted_user with rollback immediate

drop database Develop
end

Works all the time.
nikosag
nikosag
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 23
Hello,
I do the same in my production system with the following, relatively simple 4 steps job:

Step1: Alter dev database to Single user mode to prepare it for the restore. (No need to delete the database or the datafiles first.)

ALTER DATABASE DevSystem SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

Step2 Restoring Production database from the production server using a network path, containind the backup file.
(I use the MOVE command for the data and log files due to different storage paths. )

RESTORE DATABASE [DevSystem] FROM DISK = N'\\ProductionServer\BackupFolder\Dev.bak' WITH FILE = 1,
MOVE N'Datafile1' TO N'd:\MSSQL\Data\DevSystem_data1.mdf',
MOVE N'Datafile2' TO N'd:\MSSQL\Data\DevSystem_data2.ndf',
MOVE N'Logfile' TO N'd:\MSSQL\Data\DevSystem_log.LDF', NOUNLOAD, REPLACE, STATS = 90
GO

Step 3: Set the database to working state..

ALTER DATABASE DevSystem SET MULTI_USER
go

Step 4: Finally, if the dev database is on a different SQL Servel like in my case is essential to map the login username of the 1st SQL to login username of the 2nd with the following command:

sp_change_users_login update_one ,exampleusername,exampleusername
go

Regards

Nikos
thisisfutile
thisisfutile
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1342 Visits: 1031
"I started as I do with most things by over complicating the solution! "

LOL, I thought I was the only person that did that.

I usually refer to it as making 3 left-turns to go right...but at least I end up in the right position. :-)
JasonYousef
JasonYousef
Right there with Babe
Right there with Babe (753 reputation)Right there with Babe (753 reputation)Right there with Babe (753 reputation)Right there with Babe (753 reputation)Right there with Babe (753 reputation)Right there with Babe (753 reputation)Right there with Babe (753 reputation)Right there with Babe (753 reputation)

Group: General Forum Members
Points: 753 Visits: 676
That's a good one Nikos, Thanks for sharing your experience.

nikosag (10/5/2010)
Hello,
I do the same in my production system with the following, relatively simple 4 steps job:

Step1: Alter dev database to Single user mode to prepare it for the restore. (No need to delete the database or the datafiles first.)

ALTER DATABASE DevSystem SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

Step2 Restoring Production database from the production server using a network path, containind the backup file.
(I use the MOVE command for the data and log files due to different storage paths. )

RESTORE DATABASE [DevSystem] FROM DISK = N'\\ProductionServer\BackupFolder\Dev.bak' WITH FILE = 1,
MOVE N'Datafile1' TO N'd:\MSSQL\Data\DevSystem_data1.mdf',
MOVE N'Datafile2' TO N'd:\MSSQL\Data\DevSystem_data2.ndf',
MOVE N'Logfile' TO N'd:\MSSQL\Data\DevSystem_log.LDF', NOUNLOAD, REPLACE, STATS = 90
GO

Step 3: Set the database to working state..

ALTER DATABASE DevSystem SET MULTI_USER
go

Step 4: Finally, if the dev database is on a different SQL Servel like in my case is essential to map the login username of the 1st SQL to login username of the 2nd with the following command:

sp_change_users_login update_one ,exampleusername,exampleusername
go

Regards

Nikos

lloyd.tapper
lloyd.tapper
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 15
Nikos, I do pretty much the same thing that you do. However, could you explain Step #4 a bit more. The one thing I generally have trouble with is the logins and haven't gotten a satisfactory solution yet. What does this step do?


Step 4: Finally, if the dev database is on a different SQL Servel like in my case is essential to map the login username of the 1st SQL to login username of the 2nd with the following command:

sp_change_users_login update_one ,exampleusername,exampleusername
go

Regards

Nikos

SanjayAttray
SanjayAttray
SSCertifiable
SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)

Group: General Forum Members
Points: 7661 Visits: 1619
Why do this task with VB script when you can do the whole process with T-SQL scripts?

SQL DBA.
2Tall
2Tall
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6746 Visits: 1218
Hi.

Why use VB scripts.


I said not everyone would agree with my approach! Smile

The VB scripts supported what I wanted to achieve.

Kind Regards,
Phil.

-------------------------------------------------------------------------------------
A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."

Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '

Tommy Cooper

Steve Jones
Steve Jones
SSC Guru
SSC Guru (277K reputation)SSC Guru (277K reputation)SSC Guru (277K reputation)SSC Guru (277K reputation)SSC Guru (277K reputation)SSC Guru (277K reputation)SSC Guru (277K reputation)SSC Guru (277K reputation)

Group: Administrators
Points: 277577 Visits: 19896
SanjayAttray (10/5/2010)
Why do this task with VB script when you can do the whole process with T-SQL scripts?


Do you somehow think that T-SQL is "better"

I think either approach can work well. I like VB for file work as it appears cleaner to me.

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
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (122K reputation)SSC Guru (122K reputation)SSC Guru (122K reputation)SSC Guru (122K reputation)SSC Guru (122K reputation)SSC Guru (122K reputation)SSC Guru (122K reputation)SSC Guru (122K reputation)

Group: General Forum Members
Points: 122650 Visits: 18626
Nice article and an important topic. Thanks for sharing.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

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