RMAN备份数据

RMAN使用

1、 数据库状态
打开数据库,检查数据库是否处于归档模式
conn / as sysdba

SQL> startup mount
ORACLE instance started.

Total System Global Area    443592704 bytes
Fixed Size                                    1337100 bytes
Variable Size                         335546612 bytes
Database Buffers                    100663296 bytes
Redo Buffers                                6045696 bytes
Database mounted.

SQL> alter database open;
Database altered.
检查数据库是否处于归档模式
SQL> archive log list;
Database log mode                            No Archive Mode
Automatic archival                         Disabled
Archive destination                        USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence         20
Current log sequence                     22
 
调节数据库为归档模式
SQL> startup mount;
ORACLE instance started.

Total System Global Area    443592704 bytes
Fixed Size                                    1337100 bytes
Variable Size                         335546612 bytes
Database Buffers                    100663296 bytes
Redo Buffers                                6045696 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> archive log list;
Database log mode                            Archive Mode
Automatic archival                         Enabled
Archive destination                        USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence         20
Next log sequence to archive     22
Current log sequence                     22
一般在创建数据库时是不设置为ARCHIVE MODE 的。
将数据库的日志模式设置切换(Archive Mode 和No Archive Mode 之间的切换)的步骤和操作如下:
1. 关闭运行的数据库实例
SQL> shutdown
在进行日志模式切换之前,必须将运行的数据库正常关闭。
2. 备份数据库
该备份跟以后产生的日志一起用于将来的灾难恢复(很重要,如要改为归档日志模式,没有这个数据库备份,仅有日志文件是无法从该时间点恢复的)。
3. 启动数据库实例到mount 状态,但不要打开。
SQL> startup mount
4. 切换数据库日志模式。
SQL> alter database archivelog;(设置数据库为归档日志模式)或
SQL> alter database noarchivelog;(设置数据库为非归档日志模式)
5. 打开数据库
SQL> alter database open;
6. 确认数据库现在处于归档日志模式。
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination for example: $ORACLE_HOME/dbs/arch
Oldest on-line log sequence 275
Next log sequence 277
Current log sequence 278
7. 将这个时间点的redo logs 归档
SQL> archive log all;
8. 确认新产生的日志文件已在相应的归档目录下面。

9、在归档模式下,手动切换, 让在online redolog file里面的数据写到datafile里面去了;不然的话,需要联机重做日志文件满的时候才发生切换。
alter system checkpoint;

10、备份控制文件
alter database backup controlfile to trace as '/u01/orcle/a.trc';

2、使用RMAN备份数据库

(1)RMAN连接数据库

[oracle@localhost ~]$ rman target sys/china1ok nocatalog
 

(2)全备数据库

RMAN> list backup ;

specification does not match any backup in the repository

RMAN> backup database format '/u01/backup/otter/md_%U' ;

Starting backup at 10-APR-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=29 device type= DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/oradata/otter/system01.dbf
input datafile file number=00002 name=/u01/oradata/otter/sysaux01.dbf
input datafile file number=00003 name=/u01/oradata/otter/undotbs01.dbf
input datafile file number=00005 name=/u01/oradata/otter/paul01.dbf
input datafile file number=00004 name=/u01/oradata/otter/users01.dbf
channel ORA_DISK_1: starting piece 1 at 10-APR-10
channel ORA_DISK_1: finished piece 1 at 10-APR-10
piece handle=/u01/ backup/otter/md_01laom9t_1_1 tag=TAG20100410T074148 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:56
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 10-APR-10
channel ORA_DISK_1: finished piece 1 at 10-APR-10
piece handle=/u01/ backup/otter/md_02laomdh_1_1 tag=TAG20100410T074148 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-APR-10


RMAN> list backup;


List of Backup Sets
===================


BS Key    Type LV Size             Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1             Full        1015.33M     DISK                00:01:55         10-APR-10            
                BP Key: 1     Status: AVAILABLE    Compressed: NO    Tag: TAG20100410T074148
                Piece Name: /u01/ backup/otter/md_01laom9t_1_1
    List of Datafiles in backup set 1
     File LV Type Ckp SCN        Ckp Time     Name
     ---- -- ---- ---------- --------- ----
    1             Full 1183863        10-APR-10 /u01/oradata/otter/system01.dbf
    2             Full 1183863        10-APR-10 /u01/oradata/otter/sysaux01.dbf
    3             Full 1183863        10-APR-10 /u01/oradata/otter/undotbs01.dbf
    4             Full 1183863        10-APR-10 /u01/oradata/otter/users01.dbf
    5             Full 1183863        10-APR-10 /u01/oradata/otter/paul01.dbf

BS Key    Type LV Size             Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2             Full        9.36M             DISK                00:00:04         10-APR-10            
                BP Key: 2     Status: AVAILABLE    Compressed: NO    Tag: TAG20100410T074148
                Piece Name: /u01/ backup/otter/md_02laomdh_1_1
    SPFILE Included: Modification time: 10-APR-10
    SPFILE db_unique_name: OTTER
    Control File Included: Ckp SCN: 1183915            Ckp time: 10-APR-10


 

(3)部分备份数据库

RMAN> report schema;

Report of database schema for database with db_unique_name OTTER

List of Permanent Datafiles
===========================
File Size(MB) Tablespace                     RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1        680            SYSTEM                             ***         /u01/oradata/otter/system01.dbf
2        550            SYSAUX                             ***         /u01/oradata/otter/sysaux01.dbf
3        95             UNDOTBS1                         ***         /u01/oradata/otter/undotbs01.dbf
4        5                USERS                                ***         /u01/oradata/otter/users01.dbf
5        10             PAUL                                 ***         /u01/oradata/otter/paul01.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace                     Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1        29             TEMP                                 32767             /u01/oradata/otter/temp01.dbf

RMAN> backup datafile 5 format '/u01/backup/otter/otter_%U';

Starting backup at 10-APR-10
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/oradata/otter/paul01.dbf
channel ORA_DISK_1: starting piece 1 at 10-APR-10
channel ORA_DISK_1: finished piece 1 at 10-APR-10
piece handle=/u01/ backup/otter/otter_05laonp1_1_1 tag=TAG20100410T080657 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-APR-10

Starting Control File and SPFILE Autobackup at 10-APR-10
piece handle=/u01/ backup/otter/otter_c-151511358-20100410-00 comment=NONE
Finished Control File and SPFILE Autobackup at 10-APR-10

(4)、多路并发备份

run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
backup incremental level=0
format '/u01/backup/otter/p_%U'
(datafile 1 channel c1 tag=system)
(datafile 2 channel c2 tag=aux)
(datafile 3 channel c3 tag=und)
(datafile 4,5 channel c4 tag=users);
sql 'alter system archive log current';
}
执行情况
RMAN> run {
2>    allocate channel c1 type disk;
3> allocate channel c2 type disk;
4>    allocate channel c3 type disk;
5>    allocate channel c4 type disk;
6>     backup incremental level=0
7>    format '/u01/backup/otter/p_%U'
8>    (datafile 1 channel c1 tag=system)
9>    (datafile 2 channel c2 tag=aux)
10>    (datafile 3 channel c3 tag=und)
11>    (datafile 4,5 channel c4 tag=users);
12> sql 'alter system archive log current';
13> }


allocated channel: c1
channel c1: SID=37 device type= DISK

allocated channel: c2
channel c2: SID=40 device type= DISK

allocated channel: c3
channel c3: SID=43 device type= DISK

allocated channel: c4
channel c4: SID=44 device type= DISK

Starting backup at 10-APR-10
channel c1: starting incremental level 0 datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/oradata/otter/system01.dbf
channel c1: starting piece 1 at 10-APR-10
channel c2: starting incremental level 0 datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/oradata/otter/sysaux01.dbf
channel c2: starting piece 1 at 10-APR-10
channel c3: starting incremental level 0 datafile backup set
channel c3: specifying datafile(s) in backup set
input datafile file number=00003 name=/u01/oradata/otter/undotbs01.dbf
channel c3: starting piece 1 at 10-APR-10
channel c4: starting incremental level 0 datafile backup set
channel c4: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/oradata/otter/paul01.dbf
input datafile file number=00004 name=/u01/oradata/otter/users01.dbf
channel c4: starting piece 1 at 10-APR-10
channel c3: finished piece 1 at 10-APR-10
piece handle=/u01/ backup/otter/p_0blaooqu_1_1 tag=UND comment=NONE
channel c3: backup set complete, elapsed time: 00:00:06
channel c4: finished piece 1 at 10-APR-10
piece handle=/u01/ backup/otter/p_0claooqv_1_1 tag=USERS comment=NONE
channel c4: backup set complete, elapsed time: 00:00:03
channel c2: finished piece 1 at 10-APR-10
piece handle=/u01/ backup/otter/p_0alaooqt_1_1 tag=AUX comment=NONE
channel c2: backup set complete, elapsed time: 00:01:30
channel c1: finished piece 1 at 10-APR-10
piece handle=/u01/ backup/otter/p_09laooqt_1_1 tag=SYSTEM comment=NONE
channel c1: backup set complete, elapsed time: 00:01:51
Finished backup at 10-APR-10

Starting Control File and SPFILE Autobackup at 10-APR-10
piece handle=/u01/ backup/otter/otter_c-151511358-20100410-02 comment=NONE
Finished Control File and SPFILE Autobackup at 10-APR-10

sql statement: alter system archive log current
released channel: c1
released channel: c2
released channel: c3
released channel: c4

(5)、删除备份集

RMAN> delete backupset 3,4,5,6,7,8,9,10,11,12,13;

allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=37 device type= DISK

List of Backup Pieces
BP Key    BS Key    Pc# Cp# Status            Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
3             3             1     1     AVAILABLE     DISK                /u01/ backup/otter/md_03laon1k_1_1
4             4             1     1     AVAILABLE     DISK                /u01/ backup/otter/md_04laon5h_1_1
5             5             1     1     AVAILABLE     DISK                /u01/ backup/otter/otter_05laonp1_1_1
6             6             1     1     AVAILABLE     DISK                /u01/ backup/otter/otter_c-151511358-20100410-00
7             7             1     1     AVAILABLE     DISK                /u01/flash_recovery_area/OTTER/backupset/2010_04_10/o1_mf_nnndf_TAG20100410T081203_5vzjlmnz_.bkp
8             8             1     1     AVAILABLE     DISK                /u01/ backup/otter/otter_c-151511358-20100410-01
9             9             1     1     AVAILABLE     DISK                /u01/ backup/otter/p_0blaooqu_1_1
10            10            1     1     AVAILABLE     DISK                /u01/ backup/otter/p_0claooqv_1_1
11            11            1     1     AVAILABLE     DISK                /u01/ backup/otter/p_0alaooqt_1_1
12            12            1     1     AVAILABLE     DISK                /u01/ backup/otter/p_09laooqt_1_1
13            13            1     1     AVAILABLE     DISK                /u01/ backup/otter/otter_c-151511358-20100410-02

Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/u01/ backup/otter/otter_05laonp1_1_1 RECID=5 STAMP=715939617
deleted backup piece
backup piece handle=/u01/ backup/otter/otter_c-151511358-20100410-00 RECID=6 STAMP=715939619
deleted backup piece
backup piece handle=/u01/flash_recovery_area/OTTER/backupset/2010_04_10/o1_mf_nnndf_TAG20100410T081203_5vzjlmnz_.bkp RECID=7 STAMP=715939923
deleted backup piece
backup piece handle=/u01/ backup/otter/otter_c-151511358-20100410-01 RECID=8 STAMP=715939940
deleted backup piece
backup piece handle=/u01/ backup/otter/p_0blaooqu_1_1 RECID=9 STAMP=715940704
deleted backup piece
backup piece handle=/u01/ backup/otter/p_0claooqv_1_1 RECID=10 STAMP=715940706
deleted backup piece
backup piece handle=/u01/ backup/otter/p_0alaooqt_1_1 RECID=11 STAMP=715940702
deleted backup piece
backup piece handle=/u01/ backup/otter/p_09laooqt_1_1 RECID=12 STAMP=715940701
deleted backup piece
backup piece handle=/u01/ backup/otter/otter_c-151511358-20100410-02 RECID=13 STAMP=715940831
Deleted 9 objects

RMAN-06207: WARNING: 2 objects could not be deleted for DISK channel(s) due
RMAN-06208:                     to mismatched status.     Use CROSSCHECK command to fix status
RMAN-06210: List of Mismatched objects
RMAN-06211: ==========================
RMAN-06212:     Object Type     Filename/Handle
RMAN-06213: --------------- ---------------------------------------------------
RMAN-06214: Backup Piece        /u01/ backup/otter/md_03laon1k_1_1
RMAN-06214: Backup Piece        /u01/ backup/otter/md_04laon5h_1_1

(6)、备份多份文件

RMAN> backup copies 2 datafile 4 format '/u01/backup/otter/b1/b1_%U', '/u01/backup/otter/b2/b2_%U';

(7)、对备份集做备份

3、备份各种常用文件

备份datafile
bacup datafile '/u01/oradata/otter/user01.dbf' format '/u01/backup/user_%U';
 
备份tablespace
select tablespace_name, content from dba_tablespace;
bacup tablespace example,users format '/u01/backup/tbs_%U';
 
备份controlfile
configure controlfile autobackup clear;
show all;
configure controlfile autobackup on;时, 用rman备份其他文件的时候,则会自动备份controlfile和spfile文件
或使用include指令把控制文件进行备份,如:backup datafile 4 include current controlfile;
或RMAN>sql "alter database backup control file to ' '/temp/control.bin''";
 
备份spfile
controlfile autoback = on;时会自动产生备份
或backup spfile backup '/u01/backup/sp_%U';
 
备份归档日志文件archive log files
backup format '/u01/backup/ar_$t_%s_%p' archivelog all delete all input;//防止重复备份,有则删掉
 
按时间进行备份
backup archivelog from time "sysdate-15" until time "sysdate-7";
 
按sequence number进行备份
 
------------------------------------------------------------------------------------------------------------------------------------------------
让系统处于自动归档方式:
1、查看系统所处的状态
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     20
Next log sequence to archive   22
Current log sequence           22
 
2、查看归档日志存储的路径
SQL> show parameter db_recovery_file
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /home/oracle/base/flash_recove
                                                 ry_area
db_recovery_file_dest_size           big integer 2G
 
3、手动切换重做日志文件,回写磁盘上面
 SQL> alter system archive log current;
 
System altered.
 
4、查看磁盘上面的文件
[oracle@136_20 2010_04_15]$ ll -h
total 32M
-rw-r----- 1 oracle oinstall  32M Apr 15 09:56 o1_mf_1_15_5wdwm0pb_.arc
-rw-r----- 1 oracle oinstall  26K Apr 15 10:04 o1_mf_1_16_5wdx2cs0_.arc
-rw-r----- 1 oracle oinstall 1.0K Apr 15 10:05 o1_mf_1_17_5wdx2dpx_.arc
-rw-r----- 1 oracle oinstall 1.5K Apr 15 10:05 o1_mf_1_18_5wdx2hh5_.arc
-rw-r----- 1 oracle oinstall 1.0K Apr 15 10:05 o1_mf_1_19_5wdx2jrj_.arc
-rw-r----- 1 oracle oinstall 1.0K Apr 15 10:05 o1_mf_1_20_5wdx2lh5_.arc
-rw-r----- 1 oracle oinstall 1.0K Apr 15 10:05 o1_mf_1_21_5wdx2md6_.arc
-rw-r----- 1 oracle oinstall 734K Apr 15 10:08 o1_mf_1_22_5wdx8031_.arc
 
 
 

你可能感兴趣的:(数据库,备份,职场,rman,休闲)