1执解、 數(shù)據(jù)庫(kù)狀態(tài)
打開(kāi)數(shù)據(jù)庫(kù)退盯,檢查數(shù)據(jù)庫(kù)是否處于歸檔模式
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.
檢查數(shù)據(jù)庫(kù)是否處于歸檔模式
SQL> archiveloglist;
Databaselogmode????????????????????????????No Archive Mode
Automatic archival???????????????????????? Disabled
Archive destination????????????????????????USE_DB_RECOVERY_FILE_DEST
Oldest onlinelogsequence???????? 20
Currentlogsequence???????????????????? 22
調(diào)節(jié)數(shù)據(jù)庫(kù)為歸檔模式
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
一般在創(chuàng)建數(shù)據(jù)庫(kù)時(shí)是不設(shè)置為ARCHIVE MODE 的春霍。
將數(shù)據(jù)庫(kù)的日志模式設(shè)置切換(Archive Mode 和No Archive Mode 之間的切換)的步驟和操作如下:
1. 關(guān)閉運(yùn)行的數(shù)據(jù)庫(kù)實(shí)例
SQL> shutdown
在進(jìn)行日志模式切換之前语泽,必須將運(yùn)行的數(shù)據(jù)庫(kù)正常關(guān)閉端蛆。
2. 備份數(shù)據(jù)庫(kù)
該備份跟以后產(chǎn)生的日志一起用于將來(lái)的災(zāi)難恢復(fù)(很重要横媚,如要改為歸檔日志模式床三,沒(méi)有這個(gè)數(shù)據(jù)庫(kù)備份一罩,僅有日志文件是無(wú)法從該時(shí)間點(diǎn)恢復(fù)的)。
3. 啟動(dòng)數(shù)據(jù)庫(kù)實(shí)例到mount 狀態(tài)勿璃,但不要打開(kāi)擒抛。
SQL> startup mount
4. 切換數(shù)據(jù)庫(kù)日志模式。
SQL> alter database archivelog;(設(shè)置數(shù)據(jù)庫(kù)為歸檔日志模式)或
SQL> alter database noarchivelog;(設(shè)置數(shù)據(jù)庫(kù)為非歸檔日志模式)
5. 打開(kāi)數(shù)據(jù)庫(kù)
SQL> alter database open;
6. 確認(rèn)數(shù)據(jù)庫(kù)現(xiàn)在處于歸檔日志模式补疑。
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. 將這個(gè)時(shí)間點(diǎn)的redo logs 歸檔
SQL> archive log all;
8. 確認(rèn)新產(chǎn)生的日志文件已在相應(yīng)的歸檔目錄下面歧沪。
9、在歸檔模式下莲组,手動(dòng)切換, 讓在online redolog file里面的數(shù)據(jù)寫到datafile里面去了诊胞;不然的話,需要聯(lián)機(jī)重做日志文件滿的時(shí)候才發(fā)生切換。
alter system checkpoint;
10撵孤、備份控制文件
alterdatabasebackupcontrolfiletotraceas'/u01/orcle/a.trc';
2迈着、使用RMAN備份數(shù)據(jù)庫(kù)
(1)RMAN連接數(shù)據(jù)庫(kù)
[oracle@localhost ~]$rman target sys/china1ok nocatalog
(2)全備數(shù)據(jù)庫(kù)
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)部分備份數(shù)據(jù)庫(kù)
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)、多路并發(fā)備份
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';
}
執(zhí)行情況
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)、對(duì)備份集做備份
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;時(shí)奴潘, 用rman備份其他文件的時(shí)候,則會(huì)自動(dòng)備份controlfile和spfile文件
或使用include指令把控制文件進(jìn)行備份影钉,如:backup datafile 4 include current controlfile;
或RMAN>sql "alter database backup control file to ' '/temp/control.bin''";
備份spfile
controlfile autoback = on;時(shí)會(huì)自動(dòng)產(chǎn)生備份
或backup spfile backup '/u01/backup/sp_%U';
備份歸檔日志文件archive log files
backup format '/u01/backup/ar_$t_%s_%p' archivelog alldelete all input;//防止重復(fù)備份画髓,有則刪掉
按時(shí)間進(jìn)行備份
backup archivelog from time "sysdate-15" until time "sysdate-7";
按sequence number進(jìn)行備份
------------------------------------------------------------------------------------------------------------------------------------------------
讓系統(tǒng)處于自動(dòng)歸檔方式:
1、查看系統(tǒng)所處的狀態(tài)
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平委、查看歸檔日志存儲(chǔ)的路徑
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奈虾、手動(dòng)切換重做日志文件,回寫磁盤上面
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