国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > Oracle > 正文

Linux中Oracle數(shù)據(jù)庫備份

2020-07-26 14:22:53
字體:
供稿:網(wǎng)友
先來介紹一些不使用腳本我們直接使用命令備份與還原oracle數(shù)據(jù)庫
Oracle數(shù)據(jù)備份:
步驟 1 備份用戶數(shù)據(jù)。
1.使用linux系統(tǒng)下的數(shù)據(jù)庫管理員賬號連接linux終端。
2. 執(zhí)行以下語句,創(chuàng)建“bak_dir”文件夾。
復(fù)制代碼 代碼如下:

 mkdir bak_dir
 

3. 執(zhí)行以下語句,為“bak_dir”文件夾賦予讀、寫和執(zhí)行權(quán)限。
復(fù)制代碼 代碼如下:

 chmod 777 bak_dir
 

4. 執(zhí)行以下語句,以sysdba用戶登錄oracle數(shù)據(jù)庫服務(wù)器。
 sqlplus 數(shù)據(jù)庫管理員賬號/密碼@數(shù)據(jù)庫實例名 as sysdba
5. 執(zhí)行以下語句,將“bak_dir”指定為“/opt/oracle/bak_dir”。
復(fù)制代碼 代碼如下:

 create or replace directory bak_dir as '/opt/oracle/bak_dir'
 commit
 

6. 執(zhí)行以下語句,將“bak_dir”的讀、寫和執(zhí)行權(quán)限賦給xx(數(shù)據(jù)用戶名)用戶。
復(fù)制代碼 代碼如下:

 grant all on directory bak_dir to xx
 commit
 

7. 執(zhí)行以下語句,退出oracle數(shù)據(jù)庫服務(wù)器。
復(fù)制代碼 代碼如下:

quit

執(zhí)行以下語句,將sysdb用戶的表備份到“bak_dir”目錄下。
8.
復(fù)制代碼 代碼如下:

expdp xx(要導(dǎo)出表所在的數(shù)據(jù)庫用戶名)/xx(密碼)@數(shù)據(jù)庫實例名 directory=bak_dir dumpfile=expdb_xx.dmp logfile=expdb_xxlog tables=表名


 Oracle數(shù)據(jù)還原:
1.在命令行輸入:
復(fù)制代碼 代碼如下:

sqlplus "/as sysdba"

2. 執(zhí)行以下語句登錄xx數(shù)據(jù)庫,用戶名:xx,密碼:xx(請輸入當(dāng)?shù)貙嶋H密碼)
 conn xx/xx;
3.如果恢復(fù)的表中有涉及到觸發(fā)器的請停止觸發(fā)器,例:A表
復(fù)制代碼 代碼如下:

alter table A disable all triggers;
commit;
 

4. 執(zhí)行以下語句退出當(dāng)前用戶
 quit;
5. 執(zhí)行以下語句,恢復(fù)用戶數(shù)據(jù)。
復(fù)制代碼 代碼如下:

 impdp xx/xx@數(shù)據(jù)庫實例名 directory=bak_dir table_exists_action=truncate dumpfile=expdb_xx.dmp logfile=impdb_xx.log

5.在命令行輸入:sqlplus "/as sysdba"
6. 執(zhí)行以下語句登錄xx數(shù)據(jù)庫,用戶名:xx,密碼:xx(請輸入當(dāng)?shù)貙嶋H密碼)
 conn xx/xx;
7. 執(zhí)行以下語句打開被禁止的觸發(fā)器
復(fù)制代碼 代碼如下:

alter table A enable all triggers;
commit;
 

上面方法是可以實現(xiàn)我們想要的,但但大型WEB服務(wù)器肯定是要自動定時進(jìn)行備份的。
復(fù)制代碼 代碼如下:

1.--創(chuàng)建數(shù)據(jù)表空間
2.create tablespace test_data
3.logging
4.datafile '/u01/app/oradata/test/TEST.dbf'
5.size 32m
6.autoextend on
7.next 32m maxsize 2048m
8.extent management local;
9.
10.--創(chuàng)建用戶并指定表空間
11.create user TEST identified by 123
12.default tablespace test_data
13.temporary tablespace temp;
14.
15.--給用戶授予權(quán)限
16.grant connect,resource to TEST;
 

用Test用戶登錄,創(chuàng)建一個表,并插入兩條數(shù)據(jù):
復(fù)制代碼 代碼如下:

create table t1(
Id varchar(50) primary key,
title varchar(50)
);
insert into t1 values(sys_guid(),'t1');
insert into t1 values(sys_guid(),'t2');
commit;

先寫一個導(dǎo)出的腳本文件:
復(fù)制代碼 代碼如下:

export ORACLE_BASE=/u01/app
export ORACLE_HOME=/u01/app/oracle
export ORACLE_SID=TEST
export PATH=$ORACLE_HOME/bin:$PATH
d=$(date '+%Y%m%d')
exp TEST/123@TEST file=/home/oracle/backup/$d.dmp log=/home/oracle/backup/$d.log owner=TEST
zip -m /home/oracle/backup/$d.zip /home/oracle/backup/$d.dmp /home/oracle/backup/$d.log
 

前4句是設(shè)置環(huán)境變量,因為crontab定時調(diào)用時,不會使用oracle用戶的環(huán)境變量,所以要先把它們導(dǎo)進(jìn)來。第6行以當(dāng)前日期作為導(dǎo)出的文件名,例如20120626.dmp和20120626.log。第7行把這兩個文件打成一個zip包,并刪掉這兩個文件。
要用chmod命令把這個sh標(biāo)記為可執(zhí)行:
復(fù)制代碼 代碼如下:

chmod +x backup.sh
 

用oracle用戶,輸入crontab -e命令,編輯oracle用戶的任務(wù)計劃:
 代碼如下 復(fù)制代碼
1.[oracle@localhost backup]$ crontab -e
2.42 13 * * * /home/oracle/backup/backup.sh 這樣就添加了一個計劃,在每天的13點42分運行/home/oracle/backup/backup.sh。

這樣就可以了,利用linux計劃任務(wù)就實現(xiàn)了。
備份策略:
星期天 0 級
星期一,二,四,五,六 2 級
星期三 1 級
復(fù)制代碼 代碼如下:

--創(chuàng)建本地管理路徑
mkdir -p /dinglp/ora_managed/backup
mkdir -p /dinglp/ora_managed/backup
mkdir -p /dinglp/ora_managed/backup/export-

mkdir -p /dinglp/ora_managed/backup/log
mkdir -p /dinglp/ora_managed/backup/rman_backup
mkdir -p /dinglp/ora_managed/scripts
--創(chuàng)建rman表空間和rman用戶
create tablespace rman_tbs datafile '/oradata/luke/rman_tbs01.dbf' size 1024M;
create user rman_dlp identified by dlp default tablespace rman_tbs temporary tablespace temp;
grant connect,resource ,recovery_catalog_owner to rman;
--注冊catalog 數(shù)據(jù)庫
rman catalog rman_dlp/dlp
create catalog tablespace rman_tbs;
connect target sys/dg@priamry
register database;
report schema;
--設(shè)置備份參數(shù)
configure retention policy to redundancy 2;
configure retention policy to recovery window of 7 days;
--以下是備份腳本(可以通過vi進(jìn)行編輯)
dlp-> touch exp_rman.par
dlp-> touch exp_rman.sh
dlp-> touch rman_bk_LEVEL0.rcv   (數(shù)據(jù)庫0級備份)
dlp-> touch rman_bk_LEVEL0.sh
dlp-> touch rman_bk_LEVEL1.rcv (數(shù)據(jù)庫1級備份)
dlp-> touch rman_bk_LEVEL1.sh
dlp-> touch rman_bk_LEVEL2.rcv   (數(shù)據(jù)庫2級備份www.linuxidc.com)
dlp-> touch rman_bk_LEVEL2.sh
--倒出RMAN用戶數(shù)據(jù)腳本exp_rman.par
##################################################
###               exp_rman.par                 ###
##################################################
userid=rman_dlp/dlp
file=/dinglp/ora_managed/backup/export/rman.dmp
log=/dinglp/ora_managed/backup/log/rman.log
--倒出RMAN數(shù)據(jù)SHELL腳本exp_rman.sh
##################################################
###                 exp_rman.sh                ###
##################################################
#!/bin/bash
source /home/Oracle/.bash_profile
cd /dinglp/ora_managed/scripts
exp parfile=exp_rman.par
--零級備份RMAN腳本rman_bk_LEVEL0.rcv
connect catalog rman_dlp/dlp
connect target sys/dg@primary
run {
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 0 database format '/dinglp/ora_managed/backup/rman_backup/level0_%d_%s_%p_%u.bak'
tag='level 0' include current controlfile;
sql 'alter system archive log current';
backup archivelog all format '/dinglp/ora_managed/backup/rman_backup/log_%d_%s_%p_%u.bak' delete all input;
release channel d2;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;
exit;
--零級備份SHELL腳本的rman_bk_LEVEL0.sh
#####################################################################
###                   rman_bk_LEVEL0.sh                           ###
#####################################################################
#!/bin/bash
source /home/Oracle/.bash_profile
cd /dinglp/ora_managed/scripts
rman cmdfile=rman_bk_LEVEL0.rcv msglog=$HOME/backup/log/rman_bk_LEVEL0.log
./dinglp/ora_managed/script/exp_rman.sh
--一級差異增量備份RMAN腳本rman_bk_LEVEL1.rcv
connect catalog rman_dlp/dlp
connect target sys/dg@primary
run {
allocate channel d1 type disk;
backup incremental level 1 format '/dinglp/ora_managed/backup/rman_backup/level1_%d_%s_%p_%u.bak' tag = 'level 1' database;
sql 'alter system archive log current';
backup archivelog all format '/dinglp/ora_managed/backup/rman_backup/log_%d_%s_%p_%u.bak' delete all input;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;
exit;
--一級差異增量備份SHELL腳本rman_bk_LEVEL1.sh
#####################################################################
###                   rman_bk_LEVEL1.sh                           ###
#####################################################################
#!/bin/bash
source /home/Oracle/.bash_profile
cd /dinglp/ora_managed/scripts
rman cmdfile=rman_bk_LEVEL1.rcv msglog=/dinglp/ora_managed/backup/log/rman_bk_LEVEL1.log
. /dinglp/ora_managed/scripts/exp_rman.sh
--二級差異增量備份RMAN腳本rman_bk_LEVEL2.rcv
connect catalog rman_dlp/dlp
connect target sys/dg@primary
run {
allocate channel d1 type disk;
backup incremental level 2 format '/dinglp/ora_managed/backup/rman_backup/level2_%d_%s_%p_%u.bak' tag = 'level 2' database;
sql 'alter system archive log current';
backup archivelog all format '/dinglp/ora_managed/backup/rman_backup/log_%d_%s_%p_%u.bak' delete all input;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;
exit;
--二級差異增量備份SHELL腳本rman_bk_LEVEL2.sh
#####################################################################
###                   rman_bk_LEVEL2.sh                           ###
#####################################################################
#!/bin/bash
source /home/Oracle/.bash_profile
cd /dinglp/ora_managed/scripts
rman cmdfile=rman_bk_LEVEL2.rcv msglog=/dinglp/ora_managed/backup/log/rman_bk_LEVEL2.log
. /dinglp/ora_managed/scripts/exp_rman.sh
--提高RMAN增量備份性能
alter database enable block change tracking using file '/u01/app/Oracle/admin/devdb/bdump/luke.log';
desc v$block_change_tracking;
--RMAN 動態(tài)視圖
V$ARCHIVED_LOG             顯示在數(shù)據(jù)庫中已經(jīng)創(chuàng)建、備份或清除的歸檔文件。
V$BACKUP_CORRUPTION    顯示在備份集的備份過程中找到的損壞塊。
V$COPY_CORRUPTION    顯示映像復(fù)制過程中找到的損壞塊。
V$BACKUP_DATAFILE    用于通過確定各數(shù)據(jù)文件中的塊數(shù)來創(chuàng)建大小相同的備份集。通過它也可以找出數(shù)據(jù)文件中已損壞的塊數(shù)。    V$BACKUP_REDOLOG    顯示在備份集中存儲的歸檔日志。
V$BACKUP_SET     顯示已經(jīng)創(chuàng)建的備份集。
V$BACKUP_PIECE    顯示為備份集創(chuàng)建的備份片。
--如何監(jiān)視復(fù)制進(jìn)程
使用 SET COMMAND ID 命令可將服務(wù)器會話與通道聯(lián)系起來。
查詢 V$PROCESS 和 V$SESSION,可以確定會話與哪些 RMAN 通道對應(yīng)。
查詢 V$SESSION_LONGOPS,可以監(jiān)視備份和復(fù)制的進(jìn)度。
--linux下自動運行備份腳本
crontab格式簡介
第1列分鐘1~59
第2列小時1~23(0表示子夜)
第3列日1~31
第4列月1~12
第5列星期0~6(0表示星期天)
第6列要運行的命令
[root@dlp ~]# vi /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
00 22 * * 0 root /dinglp/ora_managed/scripts/rman_bk_LEVEL0.sh
00 22 * * 3 root /dinglp/ora_managed/scripts/rman_bk_LEVEL1.sh
00 22 * * 1,2,4,5,6 root /dinglp/ora_managed/scripts/rman_bk_LEVEL2.sh
--完畢,RYOHEI,2010-08-04。
 
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 马关县| 封开县| 巴里| 绥滨县| 高安市| 安塞县| 汝阳县| 绥江县| 青冈县| 上犹县| 化州市| 广水市| 毕节市| 台山市| 郸城县| 邹城市| 武陟县| 铜山县| 台湾省| 涪陵区| 沈阳市| 齐河县| 兴和县| 开封县| 石城县| 大新县| 桐梓县| 彝良县| 苍梧县| 武穴市| 惠安县| 商都县| 赫章县| 东丰县| 正宁县| 霍山县| 安宁市| 临夏县| 温宿县| 秀山| 安塞县|