IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full...

25
IT 21003 Database IT 21003 Database Administration Administration Section 09 Section 09

Transcript of IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full...

Page 1: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

IT 21003 Database AdministrationIT 21003 Database Administration

Section 09Section 09

Page 2: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and Recovery

Backup: The available options Backup: The available options

Full Consistent (cold) BackupFull Consistent (cold) Backup Database shutdown, all files copied Database shutdown, all files copied (data, control, redo logs)(data, control, redo logs)

Partial Offline BackupPartial Offline Backup Backup of individual tablespaces while Backup of individual tablespaces while offlineoffline

Partial Online (hot) BackupPartial Online (hot) Backup Individual tablespaces backed up Individual tablespaces backed up while database is open and tablespace while database is open and tablespace is onlineis online

Export/Import Logical BackupsExport/Import Logical Backups Database normally closed to users Database normally closed to users while full export takes placewhile full export takes place

Page 3: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryDetermining the FilesDetermining the Files

Information available in OPEN and MOUNT statesInformation available in OPEN and MOUNT states DatafilesDatafiles

SelectSelect name name FromFrom v&datafile; v&datafile; From control filesFrom control files

SelectSelect file_name file_name FromFrom dba_data_files; dba_data_files; From data dictionaryFrom data dictionary

Online Redo Log FilesOnline Redo Log Files SelectSelect member member FromFrom v$logfile; v$logfile;

Current Control File NamesCurrent Control File Names SelectSelect name name FromFrom v$controlfile; v$controlfile;

Page 4: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryFull Consistent BackupsFull Consistent Backups

Database must be closed during the backupDatabase must be closed during the backup Makes a block-by-block copy of all database and Makes a block-by-block copy of all database and control filescontrol files

On large databases, full backup can take a long On large databases, full backup can take a long timetime

Might not be able to have database down for this period Might not be able to have database down for this period to get a full backupto get a full backup Requires lots of storage for the backup filesRequires lots of storage for the backup files

Easier and more reliable than other methodsEasier and more reliable than other methods Can be performed in ARCHIVELOG and Can be performed in ARCHIVELOG and NOARCHIVELOG modeNOARCHIVELOG mode

Page 5: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryA Full BackupA Full Backup

Determine all files to backupDetermine all files to backup Shutdown the database in NORMAL modeShutdown the database in NORMAL mode

This ensures the database is left in a consistent stateThis ensures the database is left in a consistent state Use SHUTDOWN IMMEDIATE to quickly remove users Use SHUTDOWN IMMEDIATE to quickly remove users if neededif needed If SHUTDOWN ABORT must be used, startup in If SHUTDOWN ABORT must be used, startup in RESTRICTED mode and then SHUTDOWN NORMALRESTRICTED mode and then SHUTDOWN NORMAL

Use a backup utility or OS commands to perform Use a backup utility or OS commands to perform the backupthe backup Startup the Instance and then Open the databaseStartup the Instance and then Open the database

Page 6: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryA Partial Offline (Tablespace-Level) BackupA Partial Offline (Tablespace-Level) Backup

Only the tablespace being backed up needs to be Only the tablespace being backed up needs to be offline during the backupoffline during the backup

The SYSTEM tablespace or any tablespace containing The SYSTEM tablespace or any tablespace containing active rollback segments cannot be taken offlineactive rollback segments cannot be taken offline

Allows portions of large databases to be dumped Allows portions of large databases to be dumped during separate down periodsduring separate down periods More error prone than a full backup due to More error prone than a full backup due to increased operator input neededincreased operator input needed

Page 7: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryA Partial Offline (Tablespace-Level) BackupA Partial Offline (Tablespace-Level) Backup

Identify the datafiles belonging to the tablespace Identify the datafiles belonging to the tablespace in questionin question

SelectSelect tablespace_name, file_name, tablespace_name, file_name, FromFrom dba_data_files dba_data_files WhereWhere tablespace_name = ‘USER1_TBSPC’; tablespace_name = ‘USER1_TBSPC’;

Ensure the tablespace is offlineEnsure the tablespace is offline Alter TablespaceAlter Tablespace user1_tbspc user1_tbspc OfflineOffline;;

Use a backup utility or OS commands to perform Use a backup utility or OS commands to perform the backupthe backup Bring the tablespace back onlineBring the tablespace back online

Alter TablespaceAlter Tablespace user1_tbspc user1_tbspc OnlineOnline;;

Page 8: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryA Partial Online (Hot) BackupA Partial Online (Hot) Backup

Identify the datafiles belonging to the tablespace Identify the datafiles belonging to the tablespace in questionin question For each tablespace in turn, perform the following For each tablespace in turn, perform the following steps:steps:

Mark the beginning of the backup periodMark the beginning of the backup period Alter Tablespace user1_tbspc Begin Backup;Alter Tablespace user1_tbspc Begin Backup; Oracle stops recording checkpoints in the file headersOracle stops recording checkpoints in the file headers

Deferred rollback segments are used while is backed upDeferred rollback segments are used while is backed up

Backup all files within the tablespaceBackup all files within the tablespace Mark the end of the backup periodMark the end of the backup period

Alter Tablespace user1_tbspc End Backup;Alter Tablespace user1_tbspc End Backup; Oracle updates the file headers to the current database Oracle updates the file headers to the current database checkpointcheckpoint

Page 9: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryA Partial Online (Hot) BackupA Partial Online (Hot) Backup

The Begin and End Backup statements should be The Begin and End Backup statements should be as close in time as possibleas close in time as possible

LGWR logs whole blocks of data at any change made LGWR logs whole blocks of data at any change made within the tablespace during the backup periodwithin the tablespace during the backup period

Could result in heavy logging activityCould result in heavy logging activity

Make sure tablespaces are backed up one at a Make sure tablespaces are backed up one at a time to minimize block loggingtime to minimize block logging

Page 10: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryRecovery from a Full BackupRecovery from a Full Backup

Database is in ARCHIVELOG modeDatabase is in ARCHIVELOG mode Connect As Sysdba so that the required privileges Connect As Sysdba so that the required privileges are enabledare enabled Shutdown the databaseShutdown the database Restore all datafiles but not the Control Files and Restore all datafiles but not the Control Files and Redo Log Files from the cold backupRedo Log Files from the cold backup

Do Not Restore the redo log files, because that will Do Not Restore the redo log files, because that will overwrite the current log files, which are needed in the overwrite the current log files, which are needed in the last stages of the recoverylast stages of the recovery

Startup the instance in MOUNT stateStartup the instance in MOUNT state Startup Mount instance_name Pfile = Startup Mount instance_name Pfile = parameter_file_nameparameter_file_name

Page 11: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryRecovery from a Full BackupRecovery from a Full Backup

Recover the databaseRecover the database Use Recover DatabaseUse Recover Database

Oracle applies archived logs to roll the database forward in Oracle applies archived logs to roll the database forward in timetime If archived files are not available in the destination area, If archived files are not available in the destination area, Oracle prompts for the location of each logOracle prompts for the location of each log Having consumed the archived logs, Oracle then applies all Having consumed the archived logs, Oracle then applies all the information held in the online redo logs to complete the the information held in the online redo logs to complete the recoveryrecovery The magic words that the recovery is complete are:The magic words that the recovery is complete are:

Media Recovery Complete (MRC)Media Recovery Complete (MRC)

The database can now be made available to The database can now be made available to usersusers

Page 12: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryRecovery from a Partial (Hot or Cold) BackupRecovery from a Partial (Hot or Cold) Backup

Close the databaseClose the database Described in previous slidesDescribed in previous slides Performed in the MOUNT statePerformed in the MOUNT state All tablespaces can be recovered this wayAll tablespaces can be recovered this way

Open the databaseOpen the database Performed in an OPEN statePerformed in an OPEN state The SYSTEM tablespace and tablespaces containing The SYSTEM tablespace and tablespaces containing active rollback segments cannot be recovered in this wayactive rollback segments cannot be recovered in this way

Page 13: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryRecovery of a tablespace on a Closed databaseRecovery of a tablespace on a Closed database

Connect As Sysdba and shutdown the databaseConnect As Sysdba and shutdown the database Restore the files for the tablespace (Copy)Restore the files for the tablespace (Copy) MOUNT but do not OPEN the databaseMOUNT but do not OPEN the database Put any offline files back onlinePut any offline files back online Recover Database or Recover Tablespace Recover Database or Recover Tablespace tblspc_name;tblspc_name;

Look for the MRC resultLook for the MRC result

Alter the database to an OPEN stateAlter the database to an OPEN state

Page 14: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryRecovery of a tablespace on a Open databaseRecovery of a tablespace on a Open database

Connect As SysdbaConnect As Sysdba Take the target tablespace offlineTake the target tablespace offline Restore (copy) the files for the tablespaceRestore (copy) the files for the tablespace Recover the tablespaceRecover the tablespace Put the tablespace back onlinePut the tablespace back online

Page 15: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryThe Export/Import UtilitiesThe Export/Import Utilities

Export and Import can be used for a variety of Export and Import can be used for a variety of purposespurposes

As part of a backup strategyAs part of a backup strategy Reorganize database storageReorganize database storage Transfer data across systemsTransfer data across systems Upgrade (migrate) to different versions of OracleUpgrade (migrate) to different versions of Oracle Store data offline for future useStore data offline for future use Tablespace Point-In-Time RecoveryTablespace Point-In-Time Recovery

Page 16: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryThe Export/Import UtilitiesThe Export/Import Utilities

Essential FeaturesEssential Features Users may export/import their own objectsUsers may export/import their own objects Easiest method to restore a single tableEasiest method to restore a single table Must have privileged access to export other user’s Must have privileged access to export other user’s objectsobjects Export data file is a binary file in “internal” Oracle formatExport data file is a binary file in “internal” Oracle format Export does not drop exported objectsExport does not drop exported objects Import can create objects as well as import rowsImport can create objects as well as import rows Errors do not halt processing – is simply reportedErrors do not halt processing – is simply reported Can COMPRESS/NOCOMPRESS extentsCan COMPRESS/NOCOMPRESS extents

Page 17: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryExport LevelsExport Levels

TableTable Specific tables can be exported with or without dataSpecific tables can be exported with or without data Oracle is able to export partitions and subpartitionsOracle is able to export partitions and subpartitions

UserUser Allows export of all objects owned by one userAllows export of all objects owned by one user DBAs may use this to export a series of usersDBAs may use this to export a series of users

TablespaceTablespace Transportable TablespacesTransportable Tablespaces

DatabaseDatabase DBAs can export all objects except those owned by DBAs can export all objects except those owned by SYSSYS

Do Not Use ThisDo Not Use This

Page 18: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryUsing Export/Import as part of a Backup Using Export/Import as part of a Backup strategystrategy

A full database-level export is a logical dump of A full database-level export is a logical dump of the databasethe database

Can be very slow, usually slower than an OS physical Can be very slow, usually slower than an OS physical dumpdump Useful for recovering single tables from a DROP Useful for recovering single tables from a DROP commandcommand

Database must be OPEN to perform an exportDatabase must be OPEN to perform an export Export guarantees a read-consistent view of only single Export guarantees a read-consistent view of only single tablestables If multiple tables are being exportedIf multiple tables are being exported

Lock them in SHARE mode to prevent concurrent updates orLock them in SHARE mode to prevent concurrent updates or OPEN DATABSE in RESTRICTED modeOPEN DATABSE in RESTRICTED mode

Page 19: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryUsing Export/Import as part of a Backup Using Export/Import as part of a Backup strategystrategy

Export/Import can be used to restore/reorganize a Export/Import can be used to restore/reorganize a databasedatabase

No rollforward recovery is possibleNo rollforward recovery is possible Rebuild database after a change in the block sizeRebuild database after a change in the block size

Must prebuild rollback segments and all tablespaces firstMust prebuild rollback segments and all tablespaces first

Move tables across users; reduce fragmentation, Move tables across users; reduce fragmentation, migration effectsmigration effects

Page 20: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryMethods of ExportingMethods of Exporting

Two basic methodsTwo basic methods Interactively with a GUI utilityInteractively with a GUI utility Command LineCommand Line

Can be run at the OS command prompt or from Can be run at the OS command prompt or from within Oraclewithin Oracle Perform exports before file-level backupsPerform exports before file-level backups

This catches data block corruption problemsThis catches data block corruption problems

Page 21: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryImportImport

The only utility that can read export filesThe only utility that can read export files Can selectively import types of database objectsCan selectively import types of database objects

Useful for delaying and controlling index creationUseful for delaying and controlling index creation

Can ask to show the export file contents Can ask to show the export file contents

Page 22: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryPoints to ConsiderPoints to Consider

Good for restructuring tablesGood for restructuring tables Set up a good PCTFREE before exporting dataSet up a good PCTFREE before exporting data Drop old tables, then import under new storage Drop old tables, then import under new storage definitionsdefinitions

Can import database objects without including Can import database objects without including rowsrows

Useful for moving from development to live databasesUseful for moving from development to live databases

Import will carry on past any errorsImport will carry on past any errors Disable referential constraints during import, and Disable referential constraints during import, and recompile stored procedures as necessaryrecompile stored procedures as necessary

Page 23: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryTransportable TablespacesTransportable Tablespaces

Fast method to move tablespaces from one Fast method to move tablespaces from one database to anotherdatabase to another

Both databases must be compatible and on the same Both databases must be compatible and on the same OSOS Tablespaces must be self-containedTablespaces must be self-contained

No outside constraints or partitionsNo outside constraints or partitions

Make tablespaces READ ONLY and export the Make tablespaces READ ONLY and export the metadatametadata

Export Transport TablespaceExport Transport Tablespace = Y = Y TablespacesTablespaces = users = users FileFile = tblspc_expdata.dmp = tblspc_expdata.dmp

Use the OS to copy datafiles and export file to the Use the OS to copy datafiles and export file to the target machinetarget machine

Page 24: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryTransportable TablespacesTransportable Tablespaces

Plug in the transported tablespaces to the target Plug in the transported tablespaces to the target databasedatabase

Imp Transport_TablespaceImp Transport_Tablespace = Y = Y DatafilesDatafiles = … = … TablespacesTablespaces = … = … FileFile = … = …

Rowids in the target database are no longer Rowids in the target database are no longer uniqueunique

A rowid is only unique within a tableA rowid is only unique within a table

Transportable tablespacees are covered more in Transportable tablespacees are covered more in later course levelslater course levels

Page 25: IT 21003 Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.

Backup and RecoveryBackup and RecoveryQuestions?Questions?