rman備份腳本-九游会j9娱乐平台
ⅰ 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資料庫這樣的(照片所示)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是累計增量備份 --和比他小得級別相比(即全備份),改變的數據備份
然後根據實際情況還要將備份的策略往腳本添加
ⅲ linux下rman備份腳本問題<一>
1、 「-f」 是判斷後面接的文件存在而且是一般文件
2、 「${1}」 指的確實是執行腳本的時候跟的第一個參數 ${2}、${3}....依此類推
3、 「export」 是聲明後面的變數是「全局變數」
4、 「#」 後面是是注釋信息,去掉#號才會起作用。前面的「##」是為了美觀,並且告訴你一些腳本信息
ⅳ linux 下 oracle 10g 使用rman 每周執行一次 自動備份腳本如何編寫 希望能有解釋。
crontab -e
0 0 0 0 0 /script_path/your_backup_script.sh
每周日零時自動執行
ⅳ linux下rman備份腳本問題<二>
。。。你說的都對了
1、 「unset」 就是取消後面的變數
2、 「!」 就是取反,如果你那個目錄不存在,就創建它
3、 「$?」 這個的意思你可以去試試,執行一次錯誤的命令然後「echo $?",然後再執行一次正確的命令再」echo $?「,它的作用就是返回上一次命令的執行結果
ⅵ rman自定義備份腳本生成的bak文件怎麼恢復
先定義好備份的過期策略,然後有兩種方法。 1、可以使用schele backup。 2、自己寫腳本,並且使用操作系統上的定時任務,定期執行刪除腳本。
ⅶ 求教rman自動備份點事
求教rman自動備份點事
-- 在正式備份之前,一定按如下要求去做。
-- 版權聲明如下:
-- 可以任意拷貝、修改該備份腳本的內容,但不可以篡改作者。
各文件的作用:
1.rman_db_all.sh :
備份整個oracle資料庫,該文件會先後調用rman_db.sh,scp_rman_db_files.sh文件
2.rman_db.sh:
由rman_db_all.sh文件調用,實現用rman備份資料庫.
該腳本會首先根據環境變數的設置:
a.生成一個rman腳本文件(rman_arch_cr_g.sh), 去檢查歸檔日誌的情況
b.生成一個rman腳本文件(rman_db_backup_g.sh), 備份整個資料庫
3.scp_rman_db_files.sh:
由rman_db_all.sh文件調用,將用rman備份出的數據文件拷貝到另外一個機器上,用scp拷貝
4.os_bak_arch.sh:
用操作系統拷貝方法只備份歸檔日誌文件,該文件會先後調用os_bak_arch.sh,scp_rman_arch_files.sh文件
5.os_bak_arch.sh:
由os_bak_arch.sh文件調用,實現將新產生的歸檔日誌拷貝到指定的目錄.
6.scp_rman_arch_files.sh
由os_bak_arch.sh文件調用,將第5步的指定目錄的歸檔日誌用scp拷貝到另外一台機器上。
具體設置方法:
1.設置伺服器,使之用ssh與scp密碼登錄時不用密碼
2.在備份伺服器上創建相應的備份目錄, 為 backup_server_target, backup_server_script_target 環境變數指定的值
3.在資料庫伺服器上創建相應的目錄, 為 backup_base, script_file_target 環境變數指定的值
3.修改所有文件中的相應環境變數的值,所有文件的環境變數都一樣
4.運行前將rman_db_all.sh,rman_arch_all.sh文件前面有中文的行去掉
5.根據歸檔目錄個數的不同,適當的修改腳本
6.將所有腳本拷貝到備份伺服器的backup_server_script_target目錄下,並使所有的腳本有可執行的許可權
10.將rman_db_all.sh文件加到cron中,每天運行一次。rman_arch_all.sh也加到cron中,每30分鍾運行一次
11.根據需要修改,log_checkpoint_timeout,使之在指定的時間內歸檔,這樣可以保證在整個系統硬碟都崩潰的情況下,
只損失指定時間的記錄
備註:
1.在oracle9i下測試通過
2.每個scrip中都設置enviroment variable的原因是:用ssh時,環境變數傳不過去。
3.需要腳本找偶,因為這里發不上來。^_^
ⅷ 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的執行日誌記錄。
ⅸ rman備份shell腳本相關問題
你確定這個'date %m%d%y' 用的是數字鍵左邊的反引號``,而不是單引號''么?
你要用反引號``,才能正確的以日期形式顯示。
ⅹ 如何編寫一個windows下的oracle自動備份腳本
@echo off
echo ================================================
echo windows環境下oracle資料庫的自動備份腳本
echo 1. 使用當前日期命名備份文件。
echo 2. 自動刪除7天前的備份。
echo ================================================
::以「yyyymmdd」格式取出當前時間。
set backupdate=�te:~0,4%�te:~5,2%�te:~8,2%
::設置用戶名、密碼和要備份的資料庫。
set user=xxx
set password=123456
set database=dbtest
::創建備份目錄。
if not exist "d:\backup\data" mkdir d:\backup\data
if not exist "d:\backup\log" mkdir d:\backup\log
set datadir=d:\backup\data
set logdir=d:\backup\log
exp %user%/%password%@�tabase% file=�tadir%\data_�ckupdate%.dmp log=%logdir%\log_�ckupdate%.log
::刪除7天前的備份。
forfiles /p "�tadir%" /s /m *.* /d -7 /c "cmd /c del @path"
forfiles /p "%logdir%" /s /m *.* /d -7 /c "cmd /c del @path"
exit