1、 数据库状态
打开数据库,检查数据库是否处于归档模式
conn /assysdba
SQL> startup mount
ORACLE instance started.
Total System Global Area 443592704 bytes
FixedSize1337100 bytes
VariableSize335546612 bytes
DatabaseBuffers 100663296 bytes
Redo Buffers 6045696 bytes
Databasemounted.
SQL>alterdatabaseopen;
Databasealtered.
检查数据库是否处于归档模式
SQL> archiveloglist;
Databaselogmode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest onlinelogsequence 20
Currentlogsequence 22
调节数据库为归档模式
SQL> startup mount;
ORACLE instance started.
Total System Global Area 443592704 bytes
FixedSize1337100 bytes
VariableSize335546612 bytes
DatabaseBuffers 100663296 bytes
Redo Buffers 6045696 bytes
Databasemounted.
SQL>alterdatabasearchivelog;
Databasealtered.
SQL> archiveloglist;
Databaselogmode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest onlinelogsequence 20
Nextlogsequencetoarchive 22
Currentlogsequence 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、备份控制文件
alterdatabasebackupcontrolfiletotraceas'/u01/orcle/a.trc';
2、使用RMAN备份数据库
(1)RMAN连接数据库
[oracle@localhost ~]$rman target sys/china1ok nocatalog
(2)全备数据库
RMAN>listbackup;
specification doesnotmatchanybackupinthe repository
RMAN>backupdatabaseformat'/u01/backup/otter/md_%U';
Startingbackupat 10-APR-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=29 device type=DISK
channel ORA_DISK_1: startingfulldatafilebackupset
channel ORA_DISK_1: specifying datafile(s)inbackupset
input datafilefilenumber=00001name=/u01/oradata/otter/system01.dbf
input datafilefilenumber=00002name=/u01/oradata/otter/sysaux01.dbf
input datafilefilenumber=00003name=/u01/oradata/otter/undotbs01.dbf
input datafilefilenumber=00005name=/u01/oradata/otter/paul01.dbf
input datafilefilenumber=00004name=/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:backupsetcomplete, elapsed time: 00:01:56
channel ORA_DISK_1: startingfulldatafilebackupset
channel ORA_DISK_1: specifying datafile(s)inbackupset
includingcurrentcontrolfileinbackupset
includingcurrentSPFILEinbackupset
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:backupsetcomplete, elapsed time: 00:00:01
Finishedbackupat 10-APR-10
RMAN> listbackup;
ListofBackupSets
===================
BSKeyType LVSizeDevice Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1Full1015.33MDISK00:01:55 10-APR-10
BPKey: 1 Status: AVAILABLE Compressed: NO Tag: TAG20100410T074148
PieceName: /u01/backup/otter/md_01laom9t_1_1
ListofDatafilesinbackupset1
FileLV Type Ckp SCN Ckp TimeName
---- -- ---- ---------- --------- ----
1Full1183863 10-APR-10 /u01/oradata/otter/system01.dbf
2Full1183863 10-APR-10 /u01/oradata/otter/sysaux01.dbf
3Full1183863 10-APR-10 /u01/oradata/otter/undotbs01.dbf
4Full1183863 10-APR-10 /u01/oradata/otter/users01.dbf
5Full1183863 10-APR-10 /u01/oradata/otter/paul01.dbf
BSKeyType LVSizeDevice Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2Full9.36MDISK00:00:04 10-APR-10
BPKey: 2 Status: AVAILABLE Compressed: NO Tag: TAG20100410T074148
PieceName: /u01/backup/otter/md_02laomdh_1_1
SPFILE Included: Modification time: 10-APR-10
SPFILE db_unique_name: OTTER
ControlFileIncluded: Ckp SCN: 1183915 Ckp time: 10-APR-10
(3)部分备份数据库
RMAN> reportschema;
Reportofdatabaseschemafordatabasewithdb_unique_name OTTER
ListofPermanentDatafiles
===========================
FileSize(MB) Tablespace RB segs DatafileName
---- -------- -------------------- ------- ------------------------
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
ListofTemporaryFiles
=======================
FileSize(MB) Tablespace Maxsize(MB) TempfileName
---- -------- -------------------- ----------- --------------------
1 29TEMP32767 /u01/oradata/otter/temp01.dbf
RMAN>backupdatafile 5 format'/u01/backup/otter/otter_%U';
Startingbackupat 10-APR-10
using channel ORA_DISK_1
channel ORA_DISK_1: startingfulldatafilebackupset
channel ORA_DISK_1: specifying datafile(s)inbackupset
input datafilefilenumber=00005name=/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:backupsetcomplete, elapsed time: 00:00:01
Finishedbackupat 10-APR-10
Starting ControlFileandSPFILE Autobackup at 10-APR-10
piece handle=/u01/backup/otter/otter_c-151511358-20100410-00 comment=NONE
Finished ControlFileandSPFILE Autobackup at 10-APR-10
(4)、多路并发备份
run {
allocate channel c1 typedisk;
allocate channel c2 typedisk;
allocate channel c3 typedisk;
allocate channel c4 typedisk;
backupincrementallevel=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 typedisk;
3> allocate channel c2 typedisk;
4> allocate channel c3 typedisk;
5> allocate channel c4 typedisk;
6>backupincrementallevel=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
Startingbackupat 10-APR-10
channel c1: starting incrementallevel0 datafilebackupset
channel c1: specifying datafile(s)inbackupset
input datafilefilenumber=00001name=/u01/oradata/otter/system01.dbf
channel c1: starting piece 1 at 10-APR-10
channel c2: starting incrementallevel0 datafilebackupset
channel c2: specifying datafile(s)inbackupset
input datafilefilenumber=00002name=/u01/oradata/otter/sysaux01.dbf
channel c2: starting piece 1 at 10-APR-10
channel c3: starting incrementallevel0 datafilebackupset
channel c3: specifying datafile(s)inbackupset
input datafilefilenumber=00003name=/u01/oradata/otter/undotbs01.dbf
channel c3: starting piece 1 at 10-APR-10
channel c4: starting incrementallevel0 datafilebackupset
channel c4: specifying datafile(s)inbackupset
input datafilefilenumber=00005name=/u01/oradata/otter/paul01.dbf
input datafilefilenumber=00004name=/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:backupsetcomplete, 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:backupsetcomplete, 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:backupsetcomplete, 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:backupsetcomplete, elapsed time: 00:01:51
Finishedbackupat 10-APR-10
Starting ControlFileandSPFILE Autobackup at 10-APR-10
piece handle=/u01/backup/otter/otter_c-151511358-20100410-02 comment=NONE
Finished ControlFileandSPFILE Autobackup at 10-APR-10
sql statement:altersystem archivelogcurrent
released channel: c1
released channel: c2
released channel: c3
released channel: c4
(5)、删除备份集
RMAN>deletebackupset 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
ListofBackupPieces
BPKeyBSKeyPc# Cp# Status Device Type PieceName
------- ------- --- --- ----------- ----------- ----------
3 3 1 1 AVAILABLEDISK/u01/backup/otter/md_03laon1k_1_1
4 4 1 1 AVAILABLEDISK/u01/backup/otter/md_04laon5h_1_1
5 5 1 1 AVAILABLEDISK/u01/backup/otter/otter_05laonp1_1_1
6 6 1 1 AVAILABLEDISK/u01/backup/otter/otter_c-151511358-20100410-00
7 7 1 1 AVAILABLEDISK/u01/flash_recovery_area/OTTER/backupset/2010_04_10/o1_mf_nnndf_TAG20100410T081203_5vzjlmnz_.bkp
8 8 1 1 AVAILABLEDISK/u01/backup/otter/otter_c-151511358-20100410-01
9 9 1 1 AVAILABLEDISK/u01/backup/otter/p_0blaooqu_1_1
10 10 1 1 AVAILABLEDISK/u01/backup/otter/p_0claooqv_1_1
11 11 1 1 AVAILABLEDISK/u01/backup/otter/p_0alaooqt_1_1
12 12 1 1 AVAILABLEDISK/u01/backup/otter/p_09laooqt_1_1
13 13 1 1 AVAILABLEDISK/u01/backup/otter/otter_c-151511358-20100410-02
Do you really wanttodeletethe above objects (enter YESorNO)?yes
deletedbackuppiece
backuppiece handle=/u01/backup/otter/otter_05laonp1_1_1 RECID=5 STAMP=715939617
deletedbackuppiece
backuppiece handle=/u01/backup/otter/otter_c-151511358-20100410-00 RECID=6 STAMP=715939619
deletedbackuppiece
backuppiece handle=/u01/flash_recovery_area/OTTER/backupset/2010_04_10/o1_mf_nnndf_TAG20100410T081203_5vzjlmnz_.bkp RECID=7 STAMP=715939923
deletedbackuppiece
backuppiece handle=/u01/backup/otter/otter_c-151511358-20100410-01 RECID=8 STAMP=715939940
deletedbackuppiece
backuppiece handle=/u01/backup/otter/p_0blaooqu_1_1 RECID=9 STAMP=715940704
deletedbackuppiece
backuppiece handle=/u01/backup/otter/p_0claooqv_1_1 RECID=10 STAMP=715940706
deletedbackuppiece
backuppiece handle=/u01/backup/otter/p_0alaooqt_1_1 RECID=11 STAMP=715940702
deletedbackuppiece
backuppiece handle=/u01/backup/otter/p_09laooqt_1_1 RECID=12 STAMP=715940701
deletedbackuppiece
backuppiece handle=/u01/backup/otter/otter_c-151511358-20100410-02 RECID=13 STAMP=715940831
Deleted 9 objects
RMAN-06207: WARNING: 2 objects couldnotbe deletedforDISKchannel(s) due
RMAN-06208:tomismatched status.UseCROSSCHECK commandtofix status
RMAN-06210: ListofMismatched objects
RMAN-06211: ==========================
RMAN-06212: Object TypeFilename/Handle
RMAN-06213:--------------- ---------------------------------------------------
RMAN-06214:BackupPiece /u01/backup/otter/md_03laon1k_1_1
RMAN-06214:BackupPiece /u01/backup/otter/md_04laon5h_1_1
(6)、备份多份文件
RMAN>backupcopies 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 alldelete 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