Oracle Database Administration for Microsoft SQL Server DBAs part 18 pps

10 353 0
Oracle Database Administration for Microsoft SQL Server DBAs part 18 pps

Đang tải... (xem toàn văn)

Thông tin tài liệu

this will take all of the application databases and copy them over to the new database server. Managing Backups Managing backups is not just about purging and maintaining the retention policy, but also about knowing which backups are available for restores. Oracle provides several ways to get information about backup sets. Viewing Backups RMAN has a LIST command that will return the backup sets that are present in the catalog or control file. The listing shows the different backup pieces and details, including the checkpointed SCN, the date, full or incremental, and tablespaces that were backed up. In the following example, the archive logs were included as part of the full backup, so they are also listed. RMAN> list backup; using target database control file instead of recovery catalog List of Backup Sets =================== BS Key Type LV Size Device Type Elapsed Time Completion Time 13 Full 1.02G DISK 00:01:20 08-MAR-10 BP Key: 13 Status: AVAILABLE Compressed: NO Tag: TAG20100308T200144 Piece Name: E:\APP\FLASH_RECOVERY_AREA\MMDEV1\BACKUPSET\2010_03_08\ O1_MF_NNNDF_TAG20100308T200144_5SCC0GDZ_.BKP List of Datafiles in backup set 13 File LV Type Ckp SCN Ckp Time Name 1 Full 1760175 08-MAR-10 D:\ORADATA\MMDEV1\SYSTEM01.DBF 2 Full 1760175 08-MAR-10 D:\ORADATA\MMDEV1\SYSAUX01.DBF 3 Full 1760175 08-MAR-10 D:\ORADATA\MMDEV1\UNDOTBS01.DBF 4 Full 1760175 08-MAR-10 D:\ORADATA\MMDEV1\USERS01.DBF BS Key Type LV Size Device Type Elapsed Time Completion Time 14 Full 9.36M DISK 00:00:07 08-MAR-10 BP Key: 14 Status: AVAILABLE Compressed: NO Tag: TAG20100308T200144 Piece Name: E:\APP\FLASH_RECOVERY_AREA\MMDEV1\BACKUPSET\2010_03_08\ O1_MF_NCSNF_TAG20100308T200144_5SCC2YYM_.BKP 152 Oracle Database Administration for Microsoft SQL Server DBAs SPFILE Included: Modification time: 08-MAR-10 SPFILE db_unique_name: MMDEV1 Control File Included: Ckp SCN: 1760265 Ckp time: 08-MAR-10 BS Key Type LV Size Device Type Elapsed Time Completion Time 15 Full 9.36M DISK 00:00:06 12-MAR-10 BP Key: 15 Status: AVAILABLE Compressed: NO Tag: TAG20100312T054615 Piece Name: E:\APP\FLASH_RECOVERY_AREA\MMDEV1\BACKUPSET\2010_03_12\ O1_MF_NCSNF_TAG20100312T054615_5SNBH7Z5_.BKP SPFILE Included: Modification time: 12-MAR-10 SPFILE db_unique_name: MMDEV1 Control File Included: Ckp SCN: 1905411 Ckp time: 12-MAR-10 BS Key Size Device Type Elapsed Time Completion Time 16 58.13M DISK 00:00:09 12-MAR-10 BP Key: 16 Status: AVAILABLE Compressed: NO Tag: TAG20100312T054803 Piece Name: E:\APP\FLASH_RECOVERY_AREA\MMDEV1\BACKUPSET\2010_03_12\ O1_MF_ANNNN_TAG20100312T054803_5SNBHRFM_.BKP List of Archived Logs in backup set 16 Thrd Seq Low SCN Low Time Next SCN Next Time 1 35 1757126 08-MAR-10 1782135 09-MAR-10 1 36 1782135 09-MAR-10 1802422 09-MAR-10 1 37 1802422 09-MAR-10 1828159 10-MAR-10 1 38 1828159 10-MAR-10 1853573 10-MAR-10 1 39 1853573 10-MAR-10 1879239 11-MAR-10 1 40 1879239 11-MAR-10 1902061 12-MAR-10 1 41 1902061 12-MAR-10 1905455 12-MAR-10 To list the details about the archive logs, you can use the sequence number or SCN. RMAN> list archivelog sequence=36; List of Archived Log Copies for database with db_unique_name MMDEV1 ===================================================================== Key Thrd Seq S Low Time - 18 1 36 A 09-MAR-10 Name: E:\APP\FLASH_RECOVERY_AREA\MMDEV1\ARCHIVELOG\2010_03_09\ O1_MF_1_36_5SDDN6X8_.ARC 17 1 36 A 09-MAR-10 Name: E:\APP\PRODUCT\11.1.0\DB_1\RDBMS\ARC00036_0710094395.001 Chapter 6: Database Backup, Restore, and Recovery 153 This example shows two archive log files with the same sequence number. This means that a copy was included in the backup set and is also still in the archive log file on the database server. This is the case when the DELETE ALL INPUT option isn’t used with the backup command. But the archive logs can also be cleared out another way: by being expired and deleted, as discussed in the next section. In OEM, you can see the same backup set listing on the Backup Sets tab of Manage Current Backups, as shown in Figure 6-9. This page also offers the options to catalog additional files, so if a backup was taken and not recorded in the catalog, you can add those files, cross-check all of the archive logs and backups, delete obsolete files, and expire obsolete files. Data dictionary views and recovery catalog tables also provide views into the backup sets, to help manage backups and know which backups are available for restoring. These are also good places to check to make sure backups are running properly. 154 Oracle Database Administration for Microsoft SQL Server DBAs FIGURE 6-9. Managing backups in OEM In the RMAN catalog, RC_DATABASE has the list of databases that are registered in the catalog. RC_BACKUP_SET has the completion time of the backup, type of backup, and some additional information. It might seem like duplicate information, but remember that the RMAN catalog can keep the information for multiple databases, so a report can be run for all of the databases in the catalog. The data dictionary view v$backup_set has the same details, but it is valid for only the database server, not all of the databases registered in the catalog. The scripts are also stored in the RMAN catalog. The RC_STORED_ SCRIPT_LINE table contains details about the scripts that are scheduled. Other tables that might be useful are RC_BACKUP_SET_DETAILS, RC_ BACKUP_FILES, and RC_RMAN_BACKUP_JOB_DETAILS. The corresponding data dictionary views are v$backup_datafile, v$backup_set_details, and v$rman_backup_job_details. You can build reports from these tables outside OEM or RMAN to provide details about the backups that are running against one of the database servers or multiple databases (from the RMAN catalog). Purging Obsolete Files Keeping the catalog a manageable size is part of backup maintenance. In SQL Server, you can handle this when you schedule a database backup by setting an expire time on the backup, by number of days or on a specific date. In Oracle, the parameters REDUNDANCY and RECOVERY WINDOW set the number of backups and number of days for retention policies. Table 6-2 shows the options for expiring and deleting backup files in SQL Server and Oracle. You can run reports to get the status of the backup pieces, including which ones have been marked obsolete by the retention policy, deleted, or expired. First, run a cross-check to check the files that have been deleted or marked obsolete. Then run the RMAN DELETE OBSOLETE command to remove the files. RMAN> CROSSCHECK BACKUP; RMAN> CROSSCHECK ARCHIVELOG ALL; RMAN> DELETE EXPIRED BACKUP; If not deleting archive logs as they are backed up, delete from file system via DELETE RMAN> DELETE ARCHIVELOG ALL BACKED UP 2 TIMES; Chapter 6: Database Backup, Restore, and Recovery 155 It is possible to override the defaults for retention policies as well as force the backups to be deleted by using the RMAN DELETE FORCE command. Backing Up and Restoring Objects With SQL Server, it is typical to restore a database to get a copy of just the objects that are needed. With Oracle, restoring the database is normally to restore the full system, but there are utilities available to pull out just the objects by schema, or even at the table level. This allows you to secure backups for these objects or copy them to another system, perhaps to refresh a test environment with just the needed schema or tables. Copying Objects at the Table and Schema Level Using a SQL statement, you can create a table from an existing table for a quick backup of a table before data changes. A backup table can be defined (such as CREATE table TAB_BACKUP AS select * from TAB_PROD) with tablespaces, no logging (to avoid some of the logging in the redo logs), and with some of the other table options. The table will not include any of 156 Oracle Database Administration for Microsoft SQL Server DBAs Option SQL Server Oracle Expire Part of backup job or script parameters EXPIREDATE or RETAINDAYS (number of days or on a date) RMAN parameters REDUNDANCY and RECOVERY WINDOW (number of days or number of backups) Delete (from msdb/catalog) sp_delete_backuphistory DELETE EXPIRED Delete expired backup files Maintenance Cleanup task DELETE OBSOLETE BACKUP ARCHIVELOGS DELETE ALL INPUT TABLE 6-2. Delete and Expire Backup Options in SQL Server and Oracle the indexes, constraints, or triggers that might be on the “real” table, but it will have the same datatypes and the same data. A WHERE clause can also be defined in the CREATE table AS statement to capture data that might be archived or deleted, as an extra security blanket. SQL Server also has a couple of utilities to pull out table-level data as well as the table definitions. The bcp utility could be used copy table objects on the SQL Server side. Oracle has the Data Pump utility, which handles both exports and imports, as well as older EXP and IMP utilities. For example, you might export a schema with just the simple EXP, and remap the schema to a new user to refresh a test schema. Chapter 5 covered some other tools, such as SQL Developer, that can pull the structure information for tables and also help copy objects to another environment or schema. However, the Data Pump utilities are easier to use and generally perform better, so we’ll take a closer look at them here. Using Data Pump Since Oracle Database 10 g , the new improved version of the export and import utilities is Data Pump. You can set up a Data Pump export job to allow you to recover just a table or another object, such as a view or stored procedure. The exports include the Data Definition Language (DDL), which creates the structures of the tables, procedures, trigger, indexes, views, and other objects. Exports can also be done without data, to provide just these structures, which you can then copy to another schema or save as a backup. Data Pump does require some setup and permissions. Since the export file is being written out, it needs a directory for the file to write to. Directories are defined in the database, and permissions are given to read or write to the files for users that need to perform these tasks. If the exports and imports are being used only by the DBA for backups or refreshes, then these are privileged accounts. A job is created with each Data Pump execution. A name can be specifically given to a job to be able to view its progress. The dba_ datapump_jobs view shows the jobs. The Data Pump job can also export the full database by setting the parameter FULL=Y, and then be used to restore only a schema or table. Tablespaces and queries can also be exported. Even if you’re exporting a full schema or tablespace, you can exclude a table or object by using the EXCLUDE parameter. This is useful for skipping over history tables or very large tables that might be used only for reading or reporting. To view the Chapter 6: Database Backup, Restore, and Recovery 157 different parameters available for these utilities from the command line, execute expdp help=Y. Here are a few examples of creating a directory and exporting and importing with Data Pump from the command line: SQLPLUS> create directory DATAPUMP_DIR as '/oraexport/DB01/dpdump'; SQLPLUS> grant read, write on directory DATAPUMP_DIR to MMTEST; ## To run an datapump export from the command line ## This will export a couple of tables > expdp mmprod/mmpasswd schemas=MMPROD tables=TAB1,TAB2 directory=DATAPUMP_DIR dumpfile=exp_tables.dmp log=Exp_tables.log ## This will export one schema > expdp mmprod/mmpasswd schemas=MMPROD directory=DATAPUMP_DIR dumpfile=exp_mmprod.dmp log=Exp_mmprod.log ## To run a datapump import to refresh the ## test schema from the dump > impdp mmtest/mmpasswd remap_schema=MMPROD:MMTEST directory=DATAPUMP_DIR file=exp_mmprod.dmp log=Imp_mmtest.log Just as you can schedule RMAN backup jobs in OEM, you can also schedule Data Pump jobs. Figure 6-10 shows the selection of an export to a 158 Oracle Database Administration for Microsoft SQL Server DBAs FIGURE 6-10. Choosing what to export in OEM file, which is found under the Data Movement tab. The options are to export the database, schemas, tables, or tablespace. After selecting what to export, you can get an estimate of the disk space and set other parameters, as shown in Figure 6-11. Estimating the disk space would be useful in planning the directory space for the job, especially if you’re keeping a couple of copies of the export files. You can choose whether to use the actual data blocks or the table statistics to gather this information. You select the directory here, or you can create one if you are using an account with the appropriate permissions (the actual file name for the export file is specified in the next step). You also can choose whether or not you want a log of the export. The advanced options allow for selections of data and structures, just data, or just structures. Objects can be either included or excluded—choosing the one that makes the shortest list is recommended. Chapter 6: Database Backup, Restore, and Recovery 159 FIGURE 6-11. Defining an export job in OEM Figure 6-12 shows the OEM options for scheduling a Data Pump job. After you have set up the Data Pump job, even if it is a one-time run of the job, it will be listed in the job activity for the export jobs and other scheduled jobs. You can monitor it by clicking its name (DAILY_EXP in the example in Figure 6-12). Another option available in OEM is to set up a connection to a different database through a database link when importing, as shown in Figure 6-13. This would be run from the server to which you want to copy the objects, and the database link would be created to the source database. NOTE I am sure I don’t need to warn you about being careful with mixing production and test environments with links. Sometimes it is necessary to be able to refresh the test environment. This chapter has given you some examples of how to recover the database if something goes wrong. 160 Oracle Database Administration for Microsoft SQL Server DBAs FIGURE 6-12. Scheduling a Data Pump job in OEM Protecting Users from Users Much of the thought put into backups and recovery is to protect the system from hardware issues or even disasters, but you also need to consider what damage people can do. Developers, users, and DBAs use the database environment for development, testing, running applications, making changes, and just doing their jobs. As a DBA, you probably confirm which environment you are logged in to before making a change. You probably run an extra backup just to give yourself that extra protection in case something goes wrong. But other users may not be so cautious. They may accidentally log in to the wrong environment and drop a table or change a stored procedure. Fortunately, Oracle offers some features to assist in protecting users from themselves. Recycle Bin How many times have you pulled something out of the Windows Recycle Bin after deleting it? The Oracle recycle bin works the same way with tables that have been dropped. For example, if you were refreshing a couple of tables, and realized you dropped the wrong tables, you can retrieve those objects Chapter 6: Database Backup, Restore, and Recovery 161 FIGURE 6-13. Importing objects with OEM . table options. The table will not include any of 156 Oracle Database Administration for Microsoft SQL Server DBAs Option SQL Server Oracle Expire Part of backup job or script parameters EXPIREDATE. backups are available for restoring. These are also good places to check to make sure backups are running properly. 154 Oracle Database Administration for Microsoft SQL Server DBAs FIGURE 6-9. Managing. a 158 Oracle Database Administration for Microsoft SQL Server DBAs FIGURE 6-10. Choosing what to export in OEM file, which is found under the Data Movement tab. The options are to export the database,

Ngày đăng: 04/07/2014, 05:20

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan