RESTAURER UNE BASE SQL SERVER EN LIGNE DE COMMANDE

  • Auteur/autrice de la publication :
  • Post category:SQL
  • Commentaires de la publication :0 commentaire

__++Cas simple : les fichiers de travail de la base a restaurer sont au meme endroit que ceux de la base sauvegardée++__ /// Use « NomDeLaBaseARestaurer » Alter Database « NomDeLaBaseARestaurer » set SINGLE_USER Go RESTORE DATABASE « NomDeLaBaseARestaurer » FROM DISK = ‘D:\EplacementDeLaSauvegarde.bak’ WITH REPLACE, RECOVERY Go Alter Database « NomDeLaBaseARestaurer » set MULTI_USER Go /// __Cas où les fichiers ne sont pas au même endroit que durant la sauvegarde__ les fichiers de travail de la base a restaurer n’étaient pas au meme endroit lors de la sauvegarde 1) noter le LogicalName des fichiers renvoyé par la commande suivante /// RESTORE FILELISTONLY FROM DISK = ‘C:\Temp\EUROGESTE-VIDE.BAK’ /// 2) faire la restauration en utilisant le LogicalName précédemment note Nota : Le mode mono-utilisateur signifie que seul un utilisateur à la fois peut avoir accès à la base de données. Il est généralement destiné à des opérations de maintenance. /// Alter Database EUROGESTEFORM set SINGLE_USER Go /// /// RESTORE DATABASE EUROGESTEFORM FROM DISK = ‘C:\Temp\EUROGESTE-VIDE.BAK’ WITH MOVE ‘RYTEC_data’ TO ‘C:\SQLData\MSSQL11.SQL2012EXPRESS\MSSQL\DATA\EUROGESTEFORM.mdf’, MOVE ‘RYTEC_ldf’ TO ‘C:\SQLData\MSSQL11.SQL2012EXPRESS\MSSQL\DATA\EUROGESTEFORM.ldf’ Go /// /// Alter Database EUROGESTEFORM set MULTI_USER Go /// __SYNTAXE COMPLETE MICROSOFT__++++ /// –To Restore an Entire Database from a Full database backup (a Complete Restore): RESTORE DATABASE { database_name | @database_name_var } [ FROM [ ,…n ] ] [ WITH { [ RECOVERY | NORECOVERY | STANDBY = {standby_file_name | @standby_file_name_var } ] | , [ ,…n ] | , | , | , | , | , } [ ,…n ] ] [;] –To perform the first step of the initial restore sequence — of a piecemeal restore: RESTORE DATABASE { database_name | @database_name_var } [ ,…n ] [ FROM [ ,…n ] ] WITH PARTIAL, NORECOVERY [ , [ ,…n ] | , ] [ ,…n ] [;] –To Restore Specific Files or Filegroups: RESTORE DATABASE { database_name | @database_name_var } [ ,…n ] [ FROM [ ,…n ] ] WITH { [ RECOVERY | NORECOVERY ] [ , [ ,…n ] ] } [ ,…n ] [;] –To Restore Specific Pages: RESTORE DATABASE { database_name | @database_name_var } PAGE = ‘file:page [ ,…n ]’ [ , ] [ ,…n ] [ FROM [ ,…n ] ] WITH NORECOVERY [ , [ ,…n ] ] [;] –To Restore a Transaction Log: RESTORE LOG { database_name | @database_name_var } [ [ ,…n ] ] [ FROM [ ,…n ] ] [ WITH { [ RECOVERY | NORECOVERY | STANDBY = {standby_file_name | @standby_file_name_var } ] | , [ ,…n ] | , | , } [ ,…n ] ] [;] –To Revert a Database to a Database Snapshot: RESTORE DATABASE { database_name | @database_name_var } FROM DATABASE_SNAPSHOT = database_snapshot_name ::= { { logical_backup_device_name | @logical_backup_device_name_var } | { DISK | TAPE | URL } = { ‘physical_backup_device_name’ | @physical_backup_device_name_var } } Note: URL is the format used to specify the location and the file name for the Windows Azure Blob. Although Windows Azure storage is a service, the implementation is similar to disk and tape to allow for a consistent and seemless restore experince for all the three devices. ::= { FILE = { logical_file_name_in_backup | @logical_file_name_in_backup_var } | FILEGROUP = { logical_filegroup_name | @logical_filegroup_name_var } | READ_WRITE_FILEGROUPS } [ ,…n ]::= –Restore Operation Options MOVE ‘logical_file_name_in_backup’ TO ‘operating_system_file_name’ [ ,…n ] | REPLACE | RESTART | RESTRICTED_USER | CREDENTIAL –Backup Set Options | FILE = { backup_set_file_number | @backup_set_file_number } | PASSWORD = { password | @password_variable } –Media Set Options | MEDIANAME = { media_name | @media_name_variable } | MEDIAPASSWORD = { mediapassword | @mediapassword_variable } | BLOCKSIZE = { blocksize | @blocksize_variable } –Data Transfer Options | BUFFERCOUNT = { buffercount | @buffercount_variable } | MAXTRANSFERSIZE = { maxtransfersize | @maxtransfersize_variable } –Error Management Options | { CHECKSUM | NO_CHECKSUM } | { STOP_ON_ERROR | CONTINUE_AFTER_ERROR } –Monitoring Options | STATS [ = percentage ] –Tape Options | { REWIND | NOREWIND } | { UNLOAD | NOUNLOAD } ::= | KEEP_REPLICATION ::= | KEEP_CDC ::= | FILESTREAM ( DIRECTORY_NAME = directory_name ) ::= | ENABLE_BROKER | ERROR_BROKER_CONVERSATIONS | NEW_BROKER ::= | { STOPAT = { ‘datetime’| @datetime_var } | STOPATMARK = ‘lsn:lsn_number’ [ AFTER ‘datetime’] | STOPBEFOREMARK = ‘lsn:lsn_number’ [ AFTER ‘datetime’] } ::= | { STOPAT = { ‘datetime’| @datetime_var } | STOPATMARK = { ‘mark_name’ | ‘lsn:lsn_number’ } [ AFTER ‘datetime’] | STOPBEFOREMARK = { ‘mark_name’ | ‘lsn:lsn_number’ } [ AFTER ‘datetime’] } ///

Laisser un commentaire