|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 1:43 AM
Points: 619,
Visits: 1,065
|
|
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
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 5:20 AM
Points: 1,
Visits: 71
|
|
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.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, January 02, 2012 4:50 AM
Points: 10,
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
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 9:15 AM
Points: 56,
Visits: 487
|
|
"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.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 7:28 AM
Points: 68,
Visits: 558
|
|
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
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, April 13, 2012 2:19 PM
Points: 2,
Visits: 12
|
|
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
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Friday, March 15, 2013 2:43 PM
Points: 3,924,
Visits: 1,554
|
|
Why do this task with VB script when you can do the whole process with T-SQL scripts?
SQL DBA.
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 1:43 AM
Points: 619,
Visits: 1,065
|
|
Hi.
Why use VB scripts.
I said not everyone would agree with my approach! :)
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
|
|
|
|
|
SSC-Dedicated
           
Group: Administrators
Last Login: Today @ 1:14 AM
Points: 31,433,
Visits: 13,746
|
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 20, 2013 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|