RMAN 备份

RMAN 备份 总结

  1. 备份到特定设备类型(device type)
[oracle@XAG128 ~]$ rman target  c##backup_admin/xag123;

RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name MPCDB are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 3;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COMPRESSED BACKUPSET;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK MAXPIECESIZE 1 G MAXOPENFILES 8 RATE 100 M;
CONFIGURE CHANNEL 1 DEVICE TYPE DISK MAXPIECESIZE 2 G MAXOPENFILES 16 RATE 200 M;
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE RMAN OUTPUT TO KEEP FOR 6 DAYS;
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DISK;
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/12.2.0/db_1/dbs/snapcf_MPCDB.f'; # default

#备份到磁盘
RMAN> backup device type disk database;
  1. 备份启用压缩(as compressed backupset)
# tag='bak_2' 为标识
RMAN> 
backup device type disk tag 'bak_1' as compressed backupset database;
or
backup device type disk tag='bak_1' as compressed  backupset database;

#跳过只读
RMAN> backup device type disk tag='bak_3' as compressed  backupset database skip readonly;
  1. 备份归档
# 备份 尚未备份过两次的归档, (delete input 由  configure archivelog deletion policy to backed up 2 times to device type disk 决定)
RMAN> backup archivelog all not backed up 2 times delete input;

RMAN> backup tag='arc_1' archivelog all not backed up 2 times delete input;

  1. 备份数据+归档
#备份数据库且 备份 尚未备份过两次的归档,delete input 参数将删除已经备份过两次的归档(delete input 由  configure archivelog deletion policy to backed up 2 times to device type disk 决定)

RMAN> backup device type disk tag='bak5' as compressed  backupset database skip readonly plus archivelog not backed up 2 times delete input;
  1. 备份数据+归档+控制文件
RMAN> backup device type disk tag='bak7' as compressed  backupset database include current controlfile skip readonly plus archivelog not backed up 2 times delete input;
or
backup device type disk tag='bak7' as compressed  backupset database include current controlfile skip readonly;
backup device type disk tag='arc7' archivelog from time 'sysdate - 1';
  1. 保留2个备份集(其他删除)
RMAN> delete noprompt obsolete redundancy = 2 device type disk;

#删除2天前的歸檔
delete noprompt archivelog all completed before 'trunc(sysdate)-2';
  1. 列参数文件、控制文件备份信息
#参数文件备份信息
RMAN> list backup of spfile;
using target database control file instead of recovery catalog
List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time   
------- ---- -- ---------- ----------- ------------ ------------------
...

362     Full    18.03M     DISK        00:00:00     2018:12:1518:39:31
        BP Key: 362   Status: AVAILABLE  Compressed: NO  Tag: TAG20181215T183931
        Piece Name: /u03/fra/MPCDB/autobackup/2018_12_15/o1_mf_s_994963171_g19ph3bf_.bkp
  SPFILE Included: Modification time: 2018:12:1518:37:12
  SPFILE db_unique_name: MPCDB

#控制文件备份信息
RMAN> list backup of controlfile;
List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time   
------- ---- -- ---------- ----------- ------------ ------------------
...
362     Full    18.03M     DISK        00:00:00     2018:12:1518:39:31
        BP Key: 362   Status: AVAILABLE  Compressed: NO  Tag: TAG20181215T183931
        Piece Name: /u03/fra/MPCDB/autobackup/2018_12_15/o1_mf_s_994963171_g19ph3bf_.bkp
  Control File Included: Ckp SCN: 1948014      Ckp time: 2018:12:1518:39:31
  1. rman 命令调用命令脚本执行备份
[oracle@XAG128 ~]$ mkdir rman_log/

[oracle@XAG128 ~]$ cat backup1.cmd
backup device type disk tag=&1 archivelog from time 'sysdate - 1';
quit

[oracle@XAG128 ~]$ cat backup1.sh
#!/bin/bash
baktime=`date "+%Y%m%d_%H%M"`
logfile=/home/oracle/rman_log/$baktime.log
tag=arc_$baktime
rman target  c##backup_admin/xag123 @backup1.cmd using $tag log=$logfile

[oracle@XAG128 ~]$ chmod +x backup1.sh

[oracle@XAG128 ~]$ ls
backup1.cmd  backup1.sh  rman_log

[oracle@XAG128 ~]$ ./backup1.sh 
RMAN> 2> 
 
[oracle@XAG128 ~]$ ls /home/oracle/rman_log/
20181216_1310.log

你可能感兴趣的:(RMAN 备份)