oracle rman backup principle

RMAN backup
One, the principle of RMAN backup

1. Introduction
RMAN backup is an online hot backup tool that comes with ORACLE database. RMAN does not need to be installed. It can compress and detect data blocks and back up the changes of data blocks. It is a data block-level backup solution.

Disadvantages: If there is a bad block in the database, RMAN will automatically detect the bad block and skip the bad block, causing certain data loss. It is recommended to use expdp/impdp, ACTIVE DATAGUARD, ORACLE GOLDENGATE and other online logical data migration solutions.

RMAN backup is divided into two types: catalog and nocatalog:

nocatalog: Perform a backup directly, and record the backup information directly to the control file, which will cause the control file to grow continuously. If the control file is lost, the backup will not be restored, and the control file is at risk.

The control file data expiration time can be determined by modifying the control_file__record_keep_time parameter in the parameter file. The default value is 7days.

Recovery: nocatalog recovery, recovery of the database requires the record information of the control file. You must start the database to the mount stage before you can return to the database for recovery. If the control file is damaged, you need to recover first.

  1. Establish oracle operating environment (including init or sp file)

  2. File way to restore controlfile to the location specified by the init file

  3. startup mount

  4. rman, restore datafile

  5. alter database open resetlogs

catalog: Need to create a separate backup database, recovery catalog and backup table space, is to record the backup information directly in the backup database,

  1. Establish oracle operating environment (including init or sp file)

  2. rman ,restore controfile

  3. alter database mount

  4. rman, restore datafile

  5. alter database open resetlogs

2. Backup principle

Backup process: main process shadow process channel process

rman is a free installation tool integrated in the oracle database. It uses two data packages called sys.DBMS_RCVMAN and sys.DBMS_BACKUP_RESTORE to complete the work. Since these two data tables do not need the support of the oracle database, the database can be in the nomount state. Start RMAN.

RMAN backup principle:

When rman target/login, it will first detect the instance name in the ORACLE_SID variable, and generate an RMAN server process (channel process) and main process, shadow process in the instance. The channel process will allocate memory in pga (sometimes in sga). In the memory, each channel process will build a buffer (input, output), first read the backup file into the input buffer, and an input buffer will be used when it is full. Another input buffer, and then RMAN confirms the backup data block and pushes it into the output buffer after verifying. When the output buffer is filled, data from different data files will be mixed and written to disk or tape. Provide memory for channel process work;

Then the RMAN main process mobilizes the sys.DBMS_RCVMAN data packet to access the control file, and sets the TIME operator and checkpoint information of the check data file header before any operation, and returns such information to the RMAN main process; and RMAN is constructing The load-balancing algorithm and performance-enhancing algorithm are automatically executed before the actual backup/restore command.

Then the RMAN main process verifies the control file and some necessary information returned by the sys.DBMS_RCVMAN data packet through the sys.DBMS_BACKUP_RESTORE data packet, and transmits these information back to the RMAN server process (channel process);

The RMAN server process (channel process) creates a PL/SQL block based on the code in the recover.sql file to call the sys.DBMS_BACKUP_RESTORE data package (the power of backup) to back up the data file. The shadow process polls and scans the information between the channels. Return to the RMAN server process (channel process), the RMAN main process and distribute process work based on the load balancing algorithm between the channels.

RMAN process memory principle:

RMAN login generates channel processes. The channel processes allocate memory in pga (sometimes in sga). In the memory, each channel process builds a buffer (input, output), first read the backup file into the input buffer, an input buffer When the area is full, another input buffer will be used, and then RMAN will confirm the backup data block and verify it and then push it into the output buffer. When the output buffer is full, the data from different data files will be mixed and written to disk. Or tape.

Disk backup will use PGA as a backup buffer for channel process memory allocation. If the OS is not configured with local asynchronous I/O, you can use the DBWR_IO_SLAVES parameter to use I/O slaves to fill the input buffer of the memory.

If the DBWR_IO_SLAVES parameter is set to non-zero, RMAN will automatically allocate 4 I/O slaves to coordinate the input buffer data loading. At this time, the memory buffer used for disk backup will be withdrawn from the shared pool, and if there is a large pool, it will also be pushed into the large pool.

If the tape slave is not used, memory for the tape output buffer will be allocated in the PGA.

In order to maintain a reasonable range of memory allocation, according to the number of files to be backed up together, the following rules need to be applied to allocate the memory buffer size.

1) If the number of files in the backup set is less than or equal to 4, RMAN will allocate 4 1MB buffers for each file. The total buffer size is less than or equal to 16MB.

2) If the number of files in the backup set is more than 4 but less than or equal to 8, RMAN will allocate 4 buffers of 512KB for each file. The sum of the buffers is guaranteed to be less than or equal to 16MB.

3) If the number of multiplexed files exceeds 8, RMAN will allocate 4 buffers of 128KB for each file. This ensures that each file to be backed up occupies 512KB of buffer memory.

-Query to monitor the buffer size of each file when the backup is running:

SELECT set_count,device_type,TYPE,filename,buffer_size,buffer_count,open_time,close_time

FROM v$backup_async_io

ORDER BY set_count,TYPE,open_time,close_time;

What can be tracked in the V$SESSION_LONGOPS view is the work of the DBMS_BACKUP_RESTORE data package.

Two, RMAN parameters

RMAN> show all;

using target database control file instead of recovery catalog

RMAN configuration parameters are:

CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default


-Specify that the backup expires, and the second one is commonly used.

--CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;recover Window maintains a sufficient amount of backup, which can guarantee the recovery to any time within 7 days, and it will be marked as obsolete if it exceeds 7 days

–CONFIGURE RETENTION POLICY TO REDUNDANCY 2; Keep the latest 2 backups, more than two times will be marked as redundancy, the default is 1.

-CONFIGURE RETENTION POLICY TO NONE; No retention policy is required, clear recovery will default to the retention policy.

CONFIGURE BACKUP OPTIMIZATION OFF; # default

-The default value is off. If it is turned on, rman will perform an optimized algorithm on the backed up data files and archive files.

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

-The default device type, disk: disk, tape: SBT

CONFIGURE CONTROLFILE AUTOBACKUP ON;

-Force the database to automatically back up the control file after backing up the file or executing the command to change the database structure. The default value is off. This can prevent the control file and catalog from being lost, and the control file can still be restored.

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘%F’; # default

-Configure the backup path and backup format of the control file-Disk

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE TO ‘%F’; # default

-Configuration control file backup path and backup format-tape

CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default

-Configure the degree of parallelism-disk

CONFIGURE DEVICE TYPE SBT_TAPE PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default

-Configuration parallelism-tape

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

-Configure the number of copies of each backup of the database, each backup of Oracle can have multiple copies of exactly the same.

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; # default

-Configure the number of copies of each backup of the database, each backup of Oracle can have multiple copies of exactly the same.

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; # default

-Set the storage device type of the archive log of the database, the number of copies

CONFIGURE CHANNEL DEVICE TYPE ‘SBT_TAPE’ RATE 80 M;

-Configure the backup path and backup format of the backup file; CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT'C:…%d_DB_%u_%s_%p';

CONFIGURE MAXSETSIZE TO UNLIMITED; # default

CONFIGURE ENCRYPTION FOR DATABASE OFF; # default

CONFIGURE ENCRYPTION ALGORITHM ‘AES128’; # default

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default

--Dg archive deletion strategy CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;

CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/oracle/product/10.2/database/dbs/snapcf_essdb1.f’; # default

-Configure the storage path and file name of the snapshot file of the control file. This snapshot file is generated during the backup and is used to control the read consistency of the file

3. Common commands
1. Set environment variables
-language and time format

NLS_LANG=american

NLS_DATE_FORMAT=‘Mon DD YYYY HH24:MI:SS’

-Character set format, the character set needs to be set to connect to the uninstalled database

NLS_LANG = american_america.we8dec

2. Commonly used backup commands
backup database; --Back up the database, the default is in the flashback area

backup database format'…/%d_%U'; --Back up the database and specify the backup path

backup database include current controlfile plus archivelog delete all input; --backup data files, control files, archive logs

backup incremental level 0 database; --Differential incremental backup database

backup incremental level 0 cumulative database; - cumulative incremental backup database

backup as compressed backupset database format'/home/oracle/full.bak'; --compressed backup database

backup tablespace users format'/home/oracle/user.bak'; - backup table space

backup datafile'/opt/oracle/oradata/orcl/users01.dbf' format'/home/oracle/user.bak'; - backup data file

backup current controlfile format'/home/oracle/user.bak'; - backup control file

backup spfile format'/home/oracle/spfile.bak'; - backup parameter file

backup current controlfile plus archivelog; - backup control file and archive and then backup archive log

backup archivelog all format'/home/oracle/user.bak' delete all input; - backup archive log and delete

RMAN> backup as copy datafile 4 format ‘/u01/app/oracle/rmanbak/df_%d_%U’;

RMAN>backup archivelog sequence between50 and 120 thread1 delete input;

RMAN> backup archivelog from time “sysdate-15” until time “sysdate-7”;

Backup control file:

alter database backup controlfile to trace as ‘/oracle/jzjsctl.bak’;

—select tracefile from v p r o c e s s w h e r e a d d r i n ( s e l e c t p a d d r f r o m v process where addr in (select paddr from v processwhereaddrin(selectpaddrfromvsession where sid in (select sid from v$mystat));

-Backup flashback area

-Back up all files (control files, archive files, data files) that are located in the flashback area but not backed up, flashback log, current redo, current control files are not backed up

RMAN> backup recovery area;

-Files that have not been backed up on the backup disk, regardless of whether they are in the flashback area

RMAN> backup recovery files;

3. Commonly used recovery commands
restore database; --Restore the database

recover database; --Recover database

restore tablespace users;-restore tablespace

recover tablespace users; --Recover tablespace

restore datafile n;-restore data file

recover datafile n; --Recover data file

SET ARCHIVELOG DESTINATION TO ‘/bak2/arch5_16’;

restore archivelog sequence between 10 and 20; --Restore archive log

restore archivelog from logseq 27; restore all archive logs after log sequence 27

restore archivelog from logseq 27 until logseq 29; restore the log sequence to these archive logs from 27 to 29

restore controlfile from autobackup;-restore control file

restore spfile to'/back/log/spfile.ora' from autobackup;-restore parameter file

restore validate database;-Verify database recoverability

restore validate controlfile; --Verify the recoverability of the control file

restore validate spfile; --Verify the recoverability of the parameter file

4. View the backup set
list backup; - List all the backup sets in the database

list expired backup;-list expired backups;

list backup of database;-view database backup set

list backup of database summary;-View the detailed information of the backup set.

list backup of tablespace users;-view tablespace backup set

list backup of datafile n; --View the backup data file

list backup of controlfile;-view control file backup set

list backup of archivelog all;-view archive log backup set

list archivelog all; - view all current archive logs

list expired backup; --list all invalid backups

catalog:

1. Registered copy

catalog datafilecopy 'c: \ user01.bak';

2. Register the backup piece

catalog backuppiece ‘c:\demo_10.dbf’ ;

3. Register all backup files in a specific directory

catalog start with ‘c:\bak’;

4. Log off the backup record

change datafilecopy ‘c:\user01.bak’ uncatalog;

change controlfilecopy ‘c:\demo.ctl’ uncatalog;

change backuppiece ‘c:\demo_10.bak’ uncatalog;

5. Register the archive log

catalog archivelog ‘/u01/CCBPROD/oracle/oradata/archive/thread_2_seq_12307.2161.899944423’;

cataloged archived log

archived log file name=/u01/CCBPROD/oracle/oradata/archive/thread_2_seq_12307.2161.899944423 RECID=9578 STAMP=900068071

5. Manage backup sets
crosscheck backup to check all backup sets;

crosscheck backup of database to check the backup set of all data files;

crosscheck backup of tablespace users check the backup set of a specific tablespace;

crosscheck backup of datafile 4 Check the backup set of specific data files;

crosscheck backup of controlfile check the backup set of the control file;

crosscheck backup of spfile check the backup set of SPFILE;

crosscheck backup of archivelog sequence 3 Check the backup set of archive log;

crosscheck copy check all image copies;

crosscheck copy of database to check the image copies of all data files;

crosscheck copy of tablespace users check the image copy of a specific tablespace;

crosscheck copy of datafile 6 check the image copy of a specific data file;

crosscheck copy of archivelog sequence 4 Check the image copy of the archive log;

crosscheck copy of controlfile check the image copy of the control file;

crosscheck backup tag=‘SAT_BACKUP’;

crosscheck backup completed after ‘sysdate - 2’

crosscheck backup completed between ‘sysdate - 5’ and 'sysdate -2 ’

crosscheck backup device type sBT;

crosscheck archivelog all;

crosscheck archivelog like ‘%ARC00012.001’

crosscheck archivelog from sequence 12;

crosscheck archivelog until sequence 522;

6, delete backup
1, delete obsolete backup

delete obsolete; #present

delete noprompt obsolete; #do not prompt

2. Delete the EXPIRED backup set

delete noprompt expired backup;

3. Delete the copy of EXPIRED

delete noprompt expired copy ;

4. Delete a specific backup set

delete noprompt backupset 19;

5. Delete a specific backup piece

delete noprompt backuppiece ‘c:\test\demo1.bak’;

6. Delete all backup sets

delete noprompt backup; or

delete noprompt backupset;

7. Delete a specific image copy

delete noprompt datafilecopy'c:\test\demo.bak'; delete data file

delete noprompt controlfilecopy'c:\test\controlfile_bak.ctl'; delete control file

delete noprompt archivelog'c:\test\arc.bak'; delete archive log

delete noprompt force archivelog all completed before ‘sysdate - 7’;

8. Delete all image copies

delete noprompt copy;

9. Delete the input object after backup

backup archivelog all delete input ;

backup backupset 22 format=‘c:\test%u.bak’ delete input ;

10. Delete expired archivelog all; is to synchronize the information of the control file and the information of the actual physical file.
————————————————

Guess you like

Origin blog.csdn.net/weixin_39597541/article/details/103554204