2009-09-01 19 views
22

Ho un database SQL2005 Express che vorrei creare una copia della stessa istanza. Come fai a fare questo con una sceneggiatura?Come si esegue il backup e il ripristino di un database come copia sullo stesso server?

ho già uno script per la generazione del backup, ma il ripristino sta fallendo ...

l'errore:

Msg 3234, Level 16, State 2, Line 2 Logical file 'MyDB_data' is not part of database 'MyDB_Test'. Use RESTORE FILELISTONLY to list the logical file names.
Msg 3013, Level 16, State 1, Line 2 RESTORE DATABASE is terminating abnormally.

LA RISOLUZIONE:

RESTORE DATABASE [MyDB_Test] 
FROM DISK = 'C:\temp\SQL\MyDB.bak' 
WITH 
MOVE 'MyDB' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MyDB_Test.mdf' 
, MOVE 'MyDB_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MyDB_Test_log.ldf' 
, REPLACE; 

THE REASON:
Non ho identificato correttamente il percorso logico nel mio primo tentativo.

+0

Questo non è un errore del server bustione. Sto scrivendo un'applicazione che farà questo lavoro ... – RSolberg

+1

Ho appena aggiornato la mia risposta dopo aver visto le modifiche che hai apportato. –

risposta

38

RESTORE FILELISTONLY è un comando informativo e non è necessario per eseguire un ripristino. Un utente può utilizzarlo per capire quali sono i nomi logici per i file di dati, che possono essere utilizzati con i comandi MOVE per ripristinare il database in una nuova posizione.

Come suggerito dal messaggio di errore è necessario utilizzare RESTORE FILELISTONLY per vedere quali sono i nomi logici per il database. Il tuo comando di ripristino ha questi torti.

Ecco un esempio di lavoro di ciò che devi fare:

--backup the database 
backup database test1 to disk='c:\test1_full.bak' 

-- use the filelistonly command to work out what the logical names 
-- are to use in the MOVE commands. the logical name needs to 
-- stay the same, the physical name can change 
restore filelistonly from disk='c:\test1_full.bak' 
-------------------------------------------------- 
| LogicalName |   PhysicalName   | 
-------------------------------------------------- 
| test1   | C:\mssql\data\test1.mdf   | 
| test1_log  | C:\mssql\data\test1_log.ldf  | 
------------------------------------------------- 

restore database test2 from disk='c:\test1_full.bak' 
with move 'test1' to 'C:\mssql\data\test2.mdf', 
move 'test1_log' to 'C:\mssql\data\test2.ldf' 
Problemi correlati