当前位置:首页 » 编程软件 » rman备份脚本

rman备份脚本

发布时间: 2022-01-07 22:46:45

Ⅰ 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=%date:~0,4%%date:~5,2%%date:~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%@%DATABASE% file=%DATADIR%\data_%BACKUPDATE%.dmp log=%LOGDIR%\log_%BACKUPDATE%.log
::删除7天前的备份。
forfiles /p "%DATADIR%" /s /m *.* /d -7 /c "cmd /c del @path"
forfiles /p "%LOGDIR%" /s /m *.* /d -7 /c "cmd /c del @path"
exit

热点内容
emc存储图标 发布:2024-11-19 05:39:03 浏览:646
查询电脑主板配置怎么看 发布:2024-11-19 05:33:10 浏览:464
苹果手机怎么查看wifi密码 发布:2024-11-19 05:26:57 浏览:498
上级服务器ip英语 发布:2024-11-19 05:24:43 浏览:329
数据库是数 发布:2024-11-19 05:16:55 浏览:188
linux线程id 发布:2024-11-19 05:05:36 浏览:428
云堡垒服务器 发布:2024-11-19 05:05:31 浏览:340
php高端培训 发布:2024-11-19 05:04:11 浏览:974
源码智慧路灯 发布:2024-11-19 05:02:33 浏览:635
天翼生活登录密码是什么 发布:2024-11-19 04:51:30 浏览:96