Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Oracle 11g uses RMAN to back up the database

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Using RMAN (Recovery Manager), the backup and recovery tool that comes with Oracle, has the following advantages:

Support for incremental backup

Can automatically manage backup files

Automatic backup and recovery

Check the validity of backed up files

Configure flash recovery area (flash recovery area)

A flash recovery area is a storage area for backup and recovery data files and related information. Two parameters need to be set: db_recovery_file_dest_size (maximum capacity of the flash recovery area) and db_recovery_file_dest (the path where the flash recovery area is located).

View flash recovery area information:

SQL > show parameter db_recovery_file_dest;NAME TYPE VALUE---db_recovery_file_dest string / data/app/oracle/recovery_areadb_recovery_file_dest_size big integer 3882m

Modify the size of the flash recovery area:

SQL > alter system set db_recovery_file_dest_size=2g;System altered.SQL > show parameter db_recovery_file_dest NAME TYPE VALUE---db_recovery_file_dest string / data/app/oracle/recovery_areadb_recovery_file_dest_size big integer 2G

View usage:

SQL > select name,space_limit,space_used,number_of_files from v$recovery_file_dest NAME----SPACE_LIMIT SPACE_USED NUMBER_OF_FILES -/ data/app/oracle/recovery_area 2147483648 0

Shows that it is not in use.

You can also use this command to view details:

SQL > select file_type,percent_space_used,percent_space_reclaimable,number_of_files from v$flash_recovery_area_usage

Establish a connection from RMAN to the database

Create a rman user and authorize:

[oracle@temp-test oracle] $sqlplus / nologSQL > connect/as sysdbaConnected.SQL > create user rman identified by oracle;User created.SQL > grant resource,connect,dba to rman;Grant succeeded.SQL > quit

Log in to RMAN using the rman user:

[oracle@temp-test oracle] $rman target rman/oracleRecovery Manager: Release 11.2.0.1.0-Production on Fri Nov 3 16:59:27 2017Copyright (c) 1982, 2009, Oracle and/or its affiliates All rights reserved.connected to target database: ORCL (DBID=1486802665) RMAN >

You can also log in as follows:

[oracle@temp-test oracle] $rmanRecovery Manager: Release 11.2.0.1.0-Production on Fri Nov 3 17:00:35 2017Copyright (c) 1982, 2009, Oracle and/or its affiliates All rights reserved.RMAN > connect target system/rmanconnected to target database: ORCL (DBID=1486802665) RMAN > connect target rman/oracle

You can also use operating system authentication to connect to RMAN:

[oracle@temp-test oracle] $rman target / Recovery Manager: Release 11.2.0.1.0-Production on Fri Nov 3 17:02:52 2017Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: ORCL (DBID=1486802665) RMAN >

Configure RMAN

View the configuration parameters of RMAN:

RMAN > show all;using target database control file instead of recovery catalogRMAN configuration parameters for database with db_unique_name ORCL are:CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # defaultCONFIGURE BACKUP OPTIMIZATION OFF; # defaultCONFIGURE DEFAULT DEVICE TYPE TO DISK; # defaultCONFIGURE CONTROLFILE AUTOBACKUP OFF; # defaultCONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO'% defaultCONFIGURE DEVICE TYPE DISK PARALLELISM; # defaultCONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # defaultCONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # defaultCONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # defaultCONFIGURE MAXSETSIZE TO UNLIMITED; # defaultCONFIGURE ENCRYPTION FOR DATABASE OFF # defaultCONFIGURE ENCRYPTION ALGORITHM 'AES128'; # defaultCONFIGURE COMPRESSION ALGORITHM' BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE; # defaultCONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # defaultCONFIGURE SNAPSHOT CONTROLFILE NAME TO' / data/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f'; # default

Parameter meaning:

CONFIGURE RETENTION POLICY TO REDUNDANCY 1

The number of backup copies retained, which means that only one copy of the data file is retained and the latest backup copy is retained.

CONFIGURE DEFAULT DEVICE TYPE TO DISK

Data files are backed up to disk by default, or they can be other devices such as tape (sbt)

CONFIGURE BACKUP OPTIMIZATION OFF

Instead of using backup optimization, the effect of enabling backup optimization is that if you have already backed up the same version of a file, the file will not be backed up again. Only one backup file is retained

CONFIGURE CONTROLFILE AUTOBACKUP OFF

Do not start the automatic backup of the control file, after it is modified to ON, if the database structure changes or in the process of backing up the database, the control file will be automatically backed up to the specified directory

CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET

The number of backup channels is 1, and the backup set is used by default. The greater the number of channels, the shorter the task execution time.

If you want to modify the parameters, you can execute the following command:

Turn on backup optimization:

RMAN > CONFIGURE BACKUP OPTIMIZATION ON;new RMAN configuration parameters:CONFIGURE BACKUP OPTIMIZATION ON;new RMAN configuration parameters are successfully stored

Set the backup type to Copy, that is, image mode:

RMAN > CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY; new RMAN configuration parameters:CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY PARALLELISM 1 position new RMAN configuration parameters are successfully stored

Back up the control files to the flash recovery area:

RMAN > backup current controlfile;Starting backup at 03-NOV-17using channel ORA_DISK_1channel ORA_DISK_1: starting datafile copycopying current control fileoutput file name=/data/app/oracle/recovery_area/ORCL/controlfile/o1_mf_TAG20171103T180113_dzrhm9vk_.ctl tag=TAG20171103T180113 RECID=3 STAMP=959104874channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01Finished backup at 03-NOV-17

If you do not specify a flash recovery area, you can also specify the path manually:

Change the flash recovery area to the test directory

SQL > connect/as sysdbaConnected.SQL > show parameter db_recovery_file_dest NAME TYPE VALUE---db_recovery_file_dest string / data/app/oracle/recovery_areadb_recovery_file_dest_size big integer 2GSQL > alter system set Db_recovery_file_dest='/data/app/oracle/test' System altered.SQL > show parameter db_recovery_file_dest NAME TYPE VALUE---db_recovery_file_dest string / data / app/oracle/testdb_recovery_file_dest_size big integer 2G

Configure the disk type and backup directory to control file backups, with the path ending with% F:

RMAN > configure controlfile autobackup format for device type disk to'/ data/app/oracle/test/%F';new RMAN configuration parameters:CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO'/ data/app/oracle/test/%F';new RMAN configuration parameters are successfully stored

RMAN offline backup

RMAN offline backup requires shutting down the database and starting the database to the mount state.

[oracle@temp-test oracle] $sqlplus / nologSQL > connect/as sysdbaConnected.SQL > shutdown immediate;Database closed.Database dismounted.ORACLE instance shut down.SQL > startup mount;ORACLE instance started.Total System Global Area 1586708480 bytesFixed Size 2213736 bytesVariable Size 939526296 bytesDatabase Buffers 637534208 bytesRedo Buffers 7434240 bytesDatabase mounted.SQL > quit

Enter RMAN and back up the data:

First check the default parameters of data backup, backup method (copy or backupset), and backup format (disk or other)

RMAN > show all;using target database control file instead of recovery catalogRMAN configuration parameters for database with db_unique_name ORCL are:CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # defaultCONFIGURE BACKUP OPTIMIZATION ON;CONFIGURE DEFAULT DEVICE TYPE TO DISK; # defaultCONFIGURE CONTROLFILE AUTOBACKUP OFF; # defaultCONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO'% fit; # defaultCONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY PARALLELISM 1 switch configuration DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # defaultCONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # defaultCONFIGURE MAXSETSIZE TO UNLIMITED; # defaultCONFIGURE ENCRYPTION FOR DATABASE OFF; # defaultCONFIGURE ENCRYPTION ALGORITHM 'AES128' # defaultCONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE' DEFAULT' OPTIMIZE FOR LOAD TRUE; # defaultCONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # defaultCONFIGURE SNAPSHOT CONTROLFILE NAME TO'/ data/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f'; # default

Execute the backup command using copy, and the image copies the entire library:

RMAN > backup as copy database

If you are using the default backupset mode, you can use:

RMAN > backup as compressed backupset database

When the backup is complete, open the database:

RMAN > sql 'alter database open';sql statement: alter database open

RMAN backs up the entire database online

The online backup must set up the flash recovery area, the flash recovery area must be large enough, and the database must be in archive mode. When the database is backed up, the DML operation can be performed and can be read normally, and the new DML operation record will be in the redo log file. If the backup time is long and a large number of data changes occur during this period, the redo log will switch to write the changed data to the archive log file. The archive log here is similar to mysql's binlog, which uses backup and archive logging and complete data recovery in the event of a media failure.

Check whether the database archiving mode is enabled. It is currently closed:

SQL > archive log list;Database log mode No Archive ModeAutomatic archival DisabledArchive destination USE_DB_RECOVERY_FILE_DESTOldest online log sequence 22Current log sequence 24

Open log archiving:

SQL > alter database archivelog;alter database archivelog*ERROR at line 1:ORA-01126: database must be mounted in this instance and not open in anyinstance

Log archiving must be in mount mode, shut down the database and start to mount mode, and enable archiving mode:

SQL > shutdown immediate;Database closed.Database dismounted.ORACLE instance shut down.SQL > startup mount;ORACLE instance started.Total System Global Area 1586708480 bytesFixed Size 2213736 bytesVariable Size 1040189592 bytesDatabase Buffers 536870912 bytesRedo Buffers 7434240 bytesDatabase mounted.SQL > alter database archivelog;Database altered.SQL > alter database open;Database altered.SQL > archivelog list;Database log mode Archive ModeAutomatic archival EnabledArchive destination USE_DB_RECOVERY_FILE_DESTOldest online log sequence 22Next log sequence to archive 24Current log sequence 24

Use RMAN to back up the database online:

RMAN > backup as compressed backupset database plus archivelog delete all input

Use the backup set format for backup, and use compression, the compression ratio is about 5:1. Back up the data files, as well as the archive log files. After the backup is completed, the backed up archive log files are deleted from the storage directory and the archive space is cleared.

Back up the tablespace:

RMAN > backup tablespace users;Starting backup at 06-NOV-17using channel ORA_DISK_1channel ORA_DISK_1: starting datafile copyinput datafile file number=00004 name=/data/app/oracle/oradata/orcl/users01.dbfoutput file name=/data/app/oracle/test/ORCL/datafile/o1_mf_users_dzzxzmxv_.dbf tag=TAG20171106T134939 RECID=12 STAMP=959348980channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01Finished backup at 06-NOV-17

Use compression:

RMAN > backup as compressed backupset tablespace users

Using RMAN to back up the data file,% U means that a unique name is automatically assigned:

RMAN > backup as backupset datafile 1 format'/ data/app/backup/datafile_1_%U'

Clear the command and use it with caution

Clear the old backup file set format:

RMAN > delete obsolete; RMAN > crosscheck backupset;RMAN > delete expired backupset

Clear old backup files and all backups, copy mode:

RMAN > list datafilecopy all;RMAN > delete expired backupcopy;RMAN > crosscheck datafilecopy all;RMAN > delete expired backupcopy

If it is due to the capacity limitation of the flash recovery area, you can modify the path and capacity of the flash recovery area:

SQL > alter system set db_recovery_file_dest='/data/app/oracle/test';SQL > alter system set db_recovery_file_dest_size=10g

RMAN incremental backup

When using backup database, it is a full library backup, and each backup takes up time and disk space. The incremental backup of RMAN can solve these problems.

There are two backup levels, level 0 backup is full library backup, level 1 backup is incremental backup, generally speaking, level 1 incremental backup is required after level 0 backup.

RMAN > backup incremental level 0 database

Differential incremental backup for level 1:

RMAN > backup incremental level 1 database

Make an incremental backup of the image copy

RMAN > run {2 > backup incremental level 1 for recover of copy with tag 'incr_copy_backup' database;3 > recover copy of database with tag' incr_copy_backup';4 >}

Each time you execute this command, you can use an image to make an incremental backup of the database.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report