Wednesday, March 7, 2012

Copy Active DB to a TEST DB on same machine

I need to copy a active DB to a test db on the same machine. Can someone tell
me how to do this.
ThanksDo a backup (BACKUP DATABASE) of the database, then do a RESTORE DATABASE with a new database name
and use the MOVE option of the RESTORE command to specify new physical database file names.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Stup88" <Stup88@.discussions.microsoft.com> wrote in message
news:51E2B75B-3558-4DED-84AF-1FDEE95C703E@.microsoft.com...
>I need to copy a active DB to a test db on the same machine. Can someone tell
> me how to do this.
> Thanks|||Does the database I am backing up need to be offline or can I do that live
with people accessing it ?
"Tibor Karaszi" wrote:
> Do a backup (BACKUP DATABASE) of the database, then do a RESTORE DATABASE with a new database name
> and use the MOVE option of the RESTORE command to specify new physical database file names.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "Stup88" <Stup88@.discussions.microsoft.com> wrote in message
> news:51E2B75B-3558-4DED-84AF-1FDEE95C703E@.microsoft.com...
> >I need to copy a active DB to a test db on the same machine. Can someone tell
> > me how to do this.
> >
> > Thanks
>|||You can do it live, no problems (it will use some machine resources, of course, but not lock any
data or so).
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Stup88" <Stup88@.discussions.microsoft.com> wrote in message
news:BB4F039D-AF4F-4F01-A53D-0B52F451CF04@.microsoft.com...
> Does the database I am backing up need to be offline or can I do that live
> with people accessing it ?
> "Tibor Karaszi" wrote:
>> Do a backup (BACKUP DATABASE) of the database, then do a RESTORE DATABASE with a new database
>> name
>> and use the MOVE option of the RESTORE command to specify new physical database file names.
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://sqlblog.com/blogs/tibor_karaszi
>>
>> "Stup88" <Stup88@.discussions.microsoft.com> wrote in message
>> news:51E2B75B-3558-4DED-84AF-1FDEE95C703E@.microsoft.com...
>> >I need to copy a active DB to a test db on the same machine. Can someone tell
>> > me how to do this.
>> >
>> > Thanks
>>|||I am about to attempt this.. made the backup via enterprise manager, and
can't do the restore from that because of the move option that is required to
rename the physical db name.. this is something that has to happen correct.
if so can you give me a example of the code
DB name will be PM Database_test
Backuped DB was PM Database_be
Thanks
"Tibor Karaszi" wrote:
> You can do it live, no problems (it will use some machine resources, of course, but not lock any
> data or so).
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "Stup88" <Stup88@.discussions.microsoft.com> wrote in message
> news:BB4F039D-AF4F-4F01-A53D-0B52F451CF04@.microsoft.com...
> > Does the database I am backing up need to be offline or can I do that live
> > with people accessing it ?
> >
> > "Tibor Karaszi" wrote:
> >
> >> Do a backup (BACKUP DATABASE) of the database, then do a RESTORE DATABASE with a new database
> >> name
> >> and use the MOVE option of the RESTORE command to specify new physical database file names.
> >>
> >> --
> >> Tibor Karaszi, SQL Server MVP
> >> http://www.karaszi.com/sqlserver/default.asp
> >> http://sqlblog.com/blogs/tibor_karaszi
> >>
> >>
> >> "Stup88" <Stup88@.discussions.microsoft.com> wrote in message
> >> news:51E2B75B-3558-4DED-84AF-1FDEE95C703E@.microsoft.com...
> >> >I need to copy a active DB to a test db on the same machine. Can someone tell
> >> > me how to do this.
> >> >
> >> > Thanks
> >>
> >>
>|||Below is an example from Books Online. You need to adjust for the properties of your database, of
course:
RESTORE DATABASE AdventureWorks
FROM AdventureWorksBackups
WITH NORECOVERY,
MOVE 'AdventureWorks_Data' TO
'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\NewAdvWorks.mdf',
MOVE 'AdventureWorks_Log'
TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\NewAdvWorks.ldf'
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Stup88" <Stup88@.discussions.microsoft.com> wrote in message
news:935208BB-1489-40F4-A220-F5152C3ED683@.microsoft.com...
>I am about to attempt this.. made the backup via enterprise manager, and
> can't do the restore from that because of the move option that is required to
> rename the physical db name.. this is something that has to happen correct.
> if so can you give me a example of the code
> DB name will be PM Database_test
> Backuped DB was PM Database_be
> Thanks
> "Tibor Karaszi" wrote:
>> You can do it live, no problems (it will use some machine resources, of course, but not lock any
>> data or so).
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://sqlblog.com/blogs/tibor_karaszi
>>
>> "Stup88" <Stup88@.discussions.microsoft.com> wrote in message
>> news:BB4F039D-AF4F-4F01-A53D-0B52F451CF04@.microsoft.com...
>> > Does the database I am backing up need to be offline or can I do that live
>> > with people accessing it ?
>> >
>> > "Tibor Karaszi" wrote:
>> >
>> >> Do a backup (BACKUP DATABASE) of the database, then do a RESTORE DATABASE with a new database
>> >> name
>> >> and use the MOVE option of the RESTORE command to specify new physical database file names.
>> >>
>> >> --
>> >> Tibor Karaszi, SQL Server MVP
>> >> http://www.karaszi.com/sqlserver/default.asp
>> >> http://sqlblog.com/blogs/tibor_karaszi
>> >>
>> >>
>> >> "Stup88" <Stup88@.discussions.microsoft.com> wrote in message
>> >> news:51E2B75B-3558-4DED-84AF-1FDEE95C703E@.microsoft.com...
>> >> >I need to copy a active DB to a test db on the same machine. Can someone tell
>> >> > me how to do this.
>> >> >
>> >> > Thanks
>> >>
>> >>
>>

No comments:

Post a Comment