二、使用RMAN进行备份
1.备份数据库
RMAN> show all;
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
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 FORMAT '/u01/app/Oracle/rmanbak/df_%d_%U';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/10g/dbs/snapcf_orcl.f'; # defaul
RMAN> backup database format '/u01/app/oracle/rmanbak/whole_%d_%U'; --备份整个数据库
RMAN> backup as compressed backupset --备份整个数据库并压缩备份集
2> database format '/u01/app/oracle/rmanbak/whole_%d_%U';
RMAN> run{
2> allocate channel ch1 type disk --手动分配一个通道
3> maxpiecesize=2g; --指定备份片的大小为g
4> backup as compressed backupset --压缩备份集
5> format '/u01/app/oracle/rmanbak/whole_%d_%U' filesperset=3--指定备份集中允许容纳的文件数为个
6> database;
7> release channel ch1;} --释放通道
RMAN> configure device type disk parallelism 3; --将并行度改为
old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 3 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored
RMAN> backup as compressed backupset --并行度改为之后,自动启用了个通道
2> format '/u01/app/oracle/rmanbak/whole_%d_%U' filesperset=3
3> database;
Starting backup at 14-OCT-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=148 devtype=DISK --sid值对应v$session视图中的sid
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=146 devtype=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: sid=144 devtype=DISK
RMAN> run{
2> allocate channel ch1 type disk
3> maxpiecesize=100m; --备份片大小设置为m,则一个备份集包含多个备份片,且每个备份片大小为m
4> backup
5> format '/u01/app/oracle/rmanbak/whole_%d_%U'
6> database;
7> release channel ch1;}
RMAN> list backupset tag=TAG20101014T171115;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
21 Full 690.30M DISK 00:01:39 14-OCT-10
List of Datafiles in backup set 21
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ---------- ----
1 Full 1648791 14-OCT-10 /u01/app/oracle/oradata/orcl/system01.dbf
2 Full 1648791 14-OCT-10 /u01/app/oracle/oradata/orcl/undotbs01.dbf
3 Full 1648791 14-OCT-10 /u01/app/oracle/oradata/orcl/sysaux01.dbf
4 Full 1648791 14-OCT-10 /u01/app/oracle/oradata/orcl/users01.dbf
5 Full 1648791 14-OCT-10 /u01/app/oracle/oradata/orcl/example01.dbf
6 Full 1648791 14-OCT-10 /u01/app/oracle/oradata/orcl/tbs1.dbf
Backup Set Copy #1 of backup set 21
Device Type Elapsed Time Completion Time Compressed Tag
----------- ------------ --------------- ---------- ---
DISK 00:01:39 14-OCT-10 NO TAG20101014T171115
List of Backup Pieces for backup set 21 Copy #1
BP Key Pc# Status Piece Name
------- --- ----------- ----------
21 1 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_1_1
22 2 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_2_1
23 3 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_3_1
24 4 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_4_1
25 5 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_5_1
26 6 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_6_1
27 7 AVAILABLE /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_7_1
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
22 Full 6.80M DISK 00:00:01 14-OCT-10
BP Key: 28 Status: AVAILABLE Compressed: NO Tag: TAG20101014T171115
Piece Name: /u01/app/oracle/rmanbak/whole_ORCL_0olqen0s_1_1
Control File Included: Ckp SCN: 1648817 Ckp time: 14-OCT-10
SPFILE Included: Modification time: 14-OCT-10
-----------------------------------------------------------------------------------------------------------------------
2.备份数据文件
Oracle数据文件及表空间的管理请参考:Oracle 表空间与数据文件
RMAN> backup as copy datafile 4 --备份类型为镜像备份
2> format '/u01/app/oracle/rmanbak/df_%d_%U';
RMAN> list copy;
RMAN> backup datafile 4,5,6 format '/u01/app/oracle/rmanbak/df_%d_%U'; --备份类型为备份集
-----------------------------------------------------------------------------------------------------------------------
3.备份表空间
Oracle数据文件及表空间的管理请参考:Oracle 表空间与数据文件
RMAN> backup tablespace users,example format '/u01/app/oracle/rmanbak/tb_%d_%U';
RMAN> backup tablespace temp; --临时表空间不需要备份
Starting backup at 14-OCT-10
using channel ORA_DISK_1
using channel ORA_DISK_2
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 10/14/2010 18:56:12
RMAN-20202: tablespace not found in the recovery catalog
RMAN-06019: could not translate tablespace name "TEMP"
-----------------------------------------------------------------------------------------------------------------------
4.备份控制文件
Oracle 控制文件的详细介绍请参考:Oracle 控制文件(CONTROLFILE)
RMAN> configure controlfile autobackup on;--自动备份控制文件置为on状态,将自动备份控制文件和参数文件
old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
注:在备份system01.dbf或system表空间时将会自动备份控制文件和参数文件,即使自动备份控制文件参数为off
--单独备份控制文件及参数文件
RMAN> backup current controlfile;
--备份数据文件时包含控制文件
RMAN> backup datafile 4 include current controlfile;
RMAN> sql "alter database backup controlfile to ''/tmp/orclcontrol.bak''";
sql statement: alter database backup controlfile to ''/tmp/orclcontrol.bak''
RMAN> sql "alter database backup controlfile to trace as ''/tmp/orclcontrol.sql''";
sql statement: alter database backup controlfile to trace as ''/tmp/orclcontrol.sql''
--单独备份spfile
RMAN> backup spfile format '/u01/app/oracle/rmanbak/sp_%d_%U';
RMAN> backup copies 2 device type disk spfile;