rman備份與恢復腳本
『壹』 oracle rman備份腳本怎麼寫
在ORACLE資料庫中,RMAN備份的腳本非常多,下面介紹一例shell腳本如何通過RMAN備份,以及ftp上傳RMAN備份文件以及歸檔日誌文件的腳本。
fullback.sh 裡面調用RMAN命令做資料庫備份,它使用的cmdfile為/home/oracle/backup/bin/fullback.rcv,同時在/home/oracle/backup/logs目錄下生成日誌文件。
1: [oracle@DB-Server bin]$ more fullback.sh
2:
3: #!/bin/bash
4:
5: export ORACLE_BASE=/u01/app/oracle
6:
7: export ORACLE_SID=gps
8:
9: ORACLE_HOME=$ORACLE_BASE/proct/10.2.0/db_1; export ORACLE_HOME
10:
11: TMP=/tmp; export TMP
12:
13: TMPDIR=$TMP; export TMPDIR
14:
15: PATH=/usr/sbin:$PATH; export PATH
16:
17: PATH=$ORACLE_HOME/bin:$PATH; export PATH
18:
19: LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
20:
21: CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;
22:
23: export CLASSPATH
24:
25: TODAY=`date +%Y_%m_%d`
26:
27: rman nocatalog target / cmdfile /home/oracle/backup/bin/fullback.rcv log /home/oracle/backup/logs/fullbackup_$TODAY.log
28:
29: /home/oracle/backup/bin/ftpbackup.sh
30:
fullback.rcv文件非常簡單, 如下所示:
1: [oracle@DB-Server bin]$ more /home/oracle/backup/bin/fullback.rcv
2:
3: run{
4:
5: allocate channel c4 type disk;
6:
7: backup as compressed backupset
8:
9: skip inaccessible
10:
11: tag fullbackupwitharchivelog
12:
13: (database);
14:
15: backup current controlfile;
16:
17: backup spfile;
18:
19: sql "alter system archive log current";
20:
21: delete noprompt obsolete;
22:
23: release channel c4;
24:
25: }
26:
RMAN生成的備份文件,需要通過FTP上傳到FTP伺服器,一則資料庫伺服器沒有這么多空間存儲多天的備份,二則是出於容災、數據安全需要。
下面腳本中FTP伺服器,用戶名密碼均使用xxx替代,在實際環境中,使用具體的信息替代即可。
1: [oracle@DB-Server bin]$ more ftpbackup.sh
2:
3: #!/bin/sh、
4:
5: rm -f /home/oracle/.netrc
6:
7: date_yesterday=`date -d'yesterday' +%Y_%m_%d`
8:
9: date_today=`date +%Y_%m_%d`
10:
11: echo "default login xxxx password xxxxxx" >> /home/oracle/.netrc
12:
13: echo "macdef init" >> /home/oracle/.netrc
14:
15: echo "binary" >> /home/oracle/.netrc
16:
17: echo "cd archivelog" >> /home/oracle/.netrc
18:
19: echo "mkdir $date_yesterday" >> /home/oracle/.netrc
20:
21: echo "cd $date_yesterday" >> /home/oracle/.netrc
22:
23: echo "lcd /u04/flash_recovery_area/gps/archivelog/$date_yesterday" >> /home/oracle/.netrc
24:
25: echo "mput *" >> /home/oracle/.netrc
26:
27: echo "cd .." >> /home/oracle/.netrc
28:
29: echo "mkdir $date_today" >>/home/oracle/.netrc
30:
31: echo "cd $date_today" >>/home/oracle/.netrc
32:
33: echo "lcd /u04/flash_recovery_area/gps/archivelog/$date_today" >>/home/oracle/.netrc
34:
35: echo "mput * ">>/home/oracle/.netrc
36:
37: echo "cd .." >>/home/oracle/.netrc
38:
39: echo "cd ../backupset" >> /home/oracle/.netrc
40:
41: echo "mkdir $date_today" >> /home/oracle/.netrc
42:
43: echo "cd $date_today" >> /home/oracle/.netrc
44:
45: echo "lcd /u04/flash_recovery_area/gps/backupset/$date_today" >> /home/oracle/.netrc
46:
47: echo "mput *" >> /home/oracle/.netrc
48:
49: echo "cd .." >> /home/oracle/.netrc
50:
51: echo "cd ../autobackup" >> /home/oracle/.netrc
52:
53: echo "mkdir $date_today" >> /home/oracle/.netrc
54:
55: echo "cd $date_today" >> /home/oracle/.netrc
56:
57: echo "lcd /u04/flash_recovery_area/gps/autobackup/$date_today" >> /home/oracle/.netrc
58:
59: echo "mput *" >> /home/oracle/.netrc
60:
61: echo "quit" >> /home/oracle/.netrc
62:
63: echo "" >> /home/oracle/.netrc
64:
65: chmod 600 /home/oracle/.netrc
66:
67: ftp -i -v xxx.xxx.xxx.xxx 8021 >>/home/oracle/backup/logs/ftp$date_today.log 2>&1
68:
另外,關於歸檔日誌也需要每隔2小時上傳一次到FTP伺服器,2小時上傳一次歸檔日誌的shell腳本如下所示:
1: [oracle@DB-Server bin]$ more ftp2hours.sh
2:
3: #!/bin/sh
4:
5: rm -f /home/oracle/.netrc
6:
7: date_yesterday=`date -d'yesterday' +%Y_%m_%d`
8:
9: date_today=`date +%Y_%m_%d`
10:
11: echo "default login xxxx password xxxx" >> /home/oracle/.netrc
12:
13: echo "macdef init" >> /home/oracle/.netrc
14:
15: echo "binary" >> /home/oracle/.netrc
16:
17: echo "cd archivelog" >> /home/oracle/.netrc
18:
19: echo "mkdir $date_today" >>/home/oracle/.netrc
20:
21: echo "cd $date_today" >>/home/oracle/.netrc
22:
23: echo "lcd /u04/flash_recovery_area/gps/archivelog/$date_today" >>/home/oracle/.netrc
24:
25: echo "mput * ">>/home/oracle/.netrc
26:
27: echo "quit" >> /home/oracle/.netrc
28:
29: echo "" >> /home/oracle/.netrc
30:
31: chmod 600 /home/oracle/.netrc
32:
33: ftp -i -v xxx.xxx.xxx.xxx 8021 >>/home/oracle/backup/logs/ftp2hours.$date_today.log 2>&1
34:
最後需要將RMAN備份生成的日誌文件,以及FTP上傳備份文件以及歸檔日誌的記錄通過郵件形式發送給DBA或系統管理員,
1: [oracle@DB-Server bin]$ more chkbackandmail.sh
2: #!/bin/bash
3: rm -f /home/oracle/backup/bin/sendmail.pl
4: date_today=`date +%Y_%m_%d`
5: subject="Oracle Backup Alert Service on $date_today"
6: content="Dear colleagues,
7:
8: Attached please find the logs of xxx(xxx.xxx.xxx.xxx) oracle database backup and transfer to FTP Server(xxx.xxx.xxx.xxx), please
9: review the file and check whether the backup succeeded or not,and double check all backups have been mped to tape, many tha
10: nks
11:
12:
13:
14:
15: Best regards
16: Oracle Alert Services
17:
18: "
19: file="/home/oracle/backup/logs/fullbackup_$date_today.log,/home/oracle/backup/logs/ftp$date_today.log"
20: echo "#!/usr/bin/perl" >> /home/oracle/backup/bin/sendmail.pl
21: echo "use Mail::Sender;" >> /home/oracle/backup/bin/sendmail.pl
22: echo "\$sender = new Mail::Sender {smtp => 'xxx.xxx.xxx.xxx', from => '[email protected]'}; ">> /home/oracle/backup/bin/sendmai
23: l.pl
24: echo "\$sender->MailFile({to => '[email protected]',">> /home/oracle/backup/bin/sendmail.pl
25: echo "cc=>'[email protected],[email protected],[email protected]'," >> /home/oracle/backup/b
26: in/sendmail.pl
27: echo "subject => '$subject',">> /home/oracle/backup/bin/sendmail.pl
28: echo "msg => '$content',">> /home/oracle/backup/bin/sendmail.pl
29: echo "file => '$file'});">> /home/oracle/backup/bin/sendmail.pl
30: perl /home/oracle/backup/bin/sendmail.pl
最後在Crontab 作業裡面配置調用這些shell腳本。例如如下所示,在1:01分執行fullback.sh ,每隔兩個小時(例如0:50、2:50...)執行一次ftp2hours.sh, 在每天早上8:40執行chkbackandmail.sh 發送fullback.sh 以及ftp2hour.sh的執行日誌記錄。
『貳』 oracle資料庫這樣的(照片所示)rman備份腳本怎麼寫
只考慮備份,不考慮其他情況下:
root下的3個rman備份級別的腳本:
#cat rman_0.sql
backup incremental level 0 database;
#cat rman_1.sql
backup incremental level 1 database;
#cat rman_1c.sql
backup incremental level 1 cumulative database;
root下的調用rman腳本
#cat rman_0.sh
#!/bin/bash
su - oracle -c "rman target sys/SHUIMITAO@rabbit @/root/rman_0.sql"
#cat rman_1.sh
#!/bin/bash
su - oracle -c "rman target sys/SHUIMITAO@rabbit @/root/rman_1.sql"
#cat rman_1c.sh
#!/bin/bash
su - oracle -c "rman target sys/SHUIMITAO@rabbit @/root/rman_1c.sql"
root的計劃任務:
#crontab -e
0 1 * * 0 /root/rman_0.sh
0 2 * * 1 /root/rman_1.sh
0 2 * * 2 /root/rman_1.sh
0 3 * * 3 /root/rman_1c.sh
0 2 * * 4 /root/rman_1.sh
0 3 * * 5 /root/rman_1c.sh
0 2 * * 6 /root/rman_1.sh
11g里只有0和1兩個備份級別,請自行對應oracle低版本
level 0是full
level 1是差異增量備份 --和前一次備份比較,將這個期間改變的數據備份下來
level 1c是累計增量備份 --和比他小得級別相比(即全備份),改變的數據備份
然後根據實際情況還要將備份的策略往腳本添加
『叄』 rman備份shell腳本相關問題
你確定這個'date +%m%d%y' 用的是數字鍵左邊的反引號``,而不是單引號''么?
你要用反引號``,才能正確的以日期形式顯示。
『肆』 linux下oracle10G的rman備份及恢復,因為是初學,請寫出詳細腳本及步驟解釋
http://wenku..com/view/d0569e4ae45c3b3567ec8b3c.html
『伍』 oracle rman備份與恢復需要同步redolog嗎
1.歸檔模式Oracle資料庫有聯機重做日誌,這個日誌是記錄對資料庫所做的修改,比如插入,刪除,更新數據等,對這些操作都會記錄在聯機重做日誌里。一般資料庫至少要有2個聯機重做日誌組。當一個聯機重做日誌組被寫滿的時候,就會發生日誌切換,這時聯機重做日誌組2成為當前使用的日誌,當聯機重做日誌組2寫滿的時候,又會發生日誌切換,去寫聯機重做日誌組1,就這樣反復進行。如果資料庫處於非歸檔模式,聯機日誌在切換時就會丟棄.而在歸檔模式下,當發生日誌切換的時候,被切換的日誌會進行歸檔。比如,當前在使用聯機重做日誌1,當1寫滿的時候,發生日誌切換,開始寫聯機重做日誌2,這時聯機重做日誌1的內容會被拷貝到另外一個指定的目錄下。這個目錄叫做歸檔目錄,拷貝的文件叫歸檔重做日誌。資料庫使用歸檔方式運行時才可以進行災難性恢復。1.歸檔日誌模式和非歸檔日誌模式的區別非歸檔模式只能做冷備份,並且恢復時只能做完全備份.最近一次完全備份到系統出錯期間的數據不能恢復.歸檔模式可以做熱備份,並且可以做增量備份,可以做部分恢復.用ARCHIVELOGLIST可以查看期模式狀態時歸檔模式還是非歸檔模式.2.非歸檔模式相反非歸檔就是不保存舊事務日誌。
『陸』 oracle資料庫rman備份如何進行數據恢復
首先利用全備 恢復至上周日 再基於時間點恢復至周二 就這么簡單
『柒』 oracle怎麼用rman腳本進行備份
Oracle資料庫中rman備份腳本非常實用
查詢字元集
SQL> select * from nls_database_parameters;
NLS_CHARACTERSET
AL32UTF8
備份時字元集很重要,不然會出亂碼
一、0級備份(全備)紅色是要修改的,根據個人的存放位置。
[oracle@oracle122 script]$ cat db_bak0.rman
run
{
configure retention policy to recovery window of 8 days;
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '/home/oracle/rmanbak/%F';
allocate channel ch1 device type disk format '/home/oracle/rmanbak/inc0_%d_%s_%p_%u_%T';
backup incremental level 0 tag='level 0' database skip inaccessible filesperset 10 plus archivelog filesperset 20;
release channel ch1;
}
allocate channel for maintenance device type disk;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
delete noprompt archivelog until time 'sysdate-30';
0級運行腳本
[oracle@oracle122 script]$ cat exec_0_level.sh
ORACLE_HOSTNAME=oracle122; export ORACLE_HOSTNAME
ORACLE_BASE=/u01/app; export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/proct/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
export DATE=$(date +%Y_%m_%d)
export NLS_LANG="Simplified Chinese_china".AL32UTF8
/u01/app/oracle/proct/11.2.0/dbhome_1/bin/rman target sys/sys_admin cmdfile /home/oracle/rmanbak/script/db_bak0.rman log /home/oracle/rmanbak/script/log/rman_$DATE.log append
二、1級備份(增量)
[oracle@oracle122 script]$ cat db_bak1.rman
run
{
configure retention policy to recovery window of 8 days;
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '/home/oracle/rmanbak/%F';
allocate channel ch1 device type disk format '/home/oracle/rmanbak/inc1_%d_%s_%p_%u_%T';
backup incremental level 1 tag='level 1' database skip inaccessible filesperset 10 plus archivelog filesperset 20;
release channel ch1;
}
allocate channel for maintenance device type disk;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
delete noprompt archivelog until time 'sysdate-30';
1級運行腳本
[oracle@oracle122 script]$ cat exec_1_level.sh
ORACLE_HOSTNAME=oracle122; export ORACLE_HOSTNAME
ORACLE_BASE=/u01/app; export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/proct/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
export DATE=$(date +%Y_%m_%d)
export NLS_LANG="Simplified Chinese_china".AL32UTF8
/u01/app/oracle/proct/11.2.0/dbhome_1/bin/rman target sys/sys_admin cmdfile /home/oracle/rmanbak/script/db_bak1.rman log /home/oracle/rmanbak/script/log/rman_$DATE.log append
三、2級備份(從0級追加到現在的備份)
[oracle@oracle122 script]$ cat db_bak2.rman
run
{
configure retention policy to recovery window of 8 days;
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '/home/oracle/rmanbak/%F';
allocate channel ch1 device type disk format '/home/oracle/rmanbak/inc2_%d_%s_%p_%u_%T';
backup incremental level 2 tag='level 2' database skip inaccessible filesperset 10 plus archivelog filesperset 20 delete all input;
release channel ch1;
}
allocate channel for maintenance device type disk;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
2級運行腳本
[oracle@oracle122 script]$ cat exec_2_level.sh
ORACLE_HOSTNAME=oracle122; export ORACLE_HOSTNAME
ORACLE_BASE=/u01/app; export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/proct/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
export DATE=$(date +%Y_%m_%d)
export NLS_LANG="Simplified Chinese_china".AL32UTF8
/u01/app/oracle/proct/11.2.0/dbhome_1/bin/rman target sys/sys_admin cmdfile /home/oracle/rmanbak/script/db_bak2.rman log /home/oracle/rmanbak/script/log/rman_$DATE.log append
定時備份星期天為0級全備,星期三為2級備份,星期一,星期二,星期四,星期五,星期六為1級增量備份晚上11點開始備份
[oracle@oracle122 script]$ crontab -l
* 23 * * 0 /home/oracle/rmanbak/script/exec_0_level.sh
* 23 * * 1 /home/oracle/rmanbak/script/exec_1_level.sh
* 23 * * 2 /home/oracle/rmanbak/script/exec_1_level.sh
* 23 * * 3 /home/oracle/rmanbak/script/exec_2_level.sh
* 23 * * 4 /home/oracle/rmanbak/script/exec_1_level.sh
* 23 * * 5 /home/oracle/rmanbak/script/exec_1_level.sh
* 23 * * 6 /home/oracle/rmanbak/script/exec_1_level.sh
『捌』 Oracle 10g資料庫寫腳本如何備份和恢復數據
在windows開始-->運行中輸入cmd回車進入1、執行以下命令將資料庫導出(例如用戶名為test,密碼為test,資料庫實例為orcl,將其備份在F盤中命名為backup.dmp)exp test/test@orcl file = F:\backup.dmp2、執行以下命令將資料庫導入新的實例中(用戶名為test1,密碼為test1,實例名為test1)imp test1/test1@test1 file=F:\backup.dmp fromuser=test touser=test1
『玖』 rman自定義備份腳本生成的bak文件怎麼恢復
先定義好備份的過期策略,然後有兩種方法。 1、可以使用Schele backup。 2、自己寫腳本,並且使用操作系統上的定時任務,定期執行刪除腳本。