拓扑园

  • O&M
    • Universal部署
    • PHP+VUE+Laravel相关
  • Oracle性能优化
  • Oracle项目案例
    • Oracle近期项目案例(目录)
    • Oracle实战问题解析(目录)
    • Oracle数据库名变更流程(2种方式)
    • Oracle数据库目录更换流程(使用Oracle的clone工具)
    • Oracle数据库迁移方案(目录)
    • 标准化文档系列
  • Oracle基础知识
    • LLL的Oracle培训(分类)
    • LLL的docker培训(分类)
    • 标准化文档系列--(分类)
    • Oracle核心经典分析(分类)
    • 图灵小队----(分类并包含以下文章)
    • --MySQL8.0/Oracle/Memcached/Redis等安装配置于RHEL/OL6/7/8.X系列-运行环境最优配置
    • --PG安装配置于RHEL/9X系列-运行环境最优配置
    • --自动维护任务详解-开启、关闭信息统计收集(统计信息)
    • --图灵小队—Oracle/PostgreSQL下创建一个用户测试表(自行定义数据行)
    • --图灵小队-Oracle存储过程导出表的明细_UTL_FILE(文章)
    • --图灵小队-Oracle数据库删除/卸载操作指南(文章)
    • --图灵小队-Oracle常用性能查询SQL语句(文章)
    • --图灵小队-Oracle数据库上线前检查(文章)
    • --图灵小队-Oracle常用SQL语句(文章)
    • --图灵小队—Linux/Oracle脚本/MySQL合集(持续更新)
    • --图灵小队-Oracle技巧记录(文章)
    • ADG
    • RAC
    • ASM
    • OGG
    • RMAN
    • EXPDP/IMPDP
    • 工厂数据导入导出系列
  • MySQL
    • MySQL数据库规范
    • MySQL项目案例
    • MySQL安装配置
    • MYSQL集群项目
    • MySQL常见处理
    • MySQL-Sysbench专题
    • MySQL-Percona Toolkit专题
  • Linux
    • Shell编程
    • kubernetes
    • docker
    • Linux
    • PHP
    • Nginx
    • haproxy
    • mail
    • 网站
    • 域名
    • 网址收藏
  • 数据中心
    • 新框架系统集合
    • 工作文档
    • EBS数据文件扩容
    • VMware虚拟化
    • EBS系列
    • 大数据
    • SVN
    • zabbix
    • SAP
    • 备份相关
    • FC交换机
    • SVN
  • K-Studing
    • D8-Python学习
    • Oracle/MySQl等面试题
    • LG-MySQL
    • LG-Docker/K8S
    • LG-PostgreSQL
    • LG-ORACLE_BBED
    • LG-ORACLE
    • LG-Elasticsearch(ES)+ELK
    • Oracle-19C-OCP
    • WERN_ORACLE培训
    • redis数据库
    • Nginx培训学习系列
  • 其他
    • 外研英语4年级下册-听力
    • 影视系列
    • 如何使用iTunes软件通过抓包下载旧版本的ios的app
天高任鸟飞
Oracle/MySQL数据库恢复/数据迁移/生产规范报告技术交流:TEL:18562510581(微信同号);加微信入群
  1. 首页
  2. 数据中心
  3. 备份相关
  4. 正文

ORACLE服务器备份脚本(讲解)

2020年2月11日 1958点热度 1人点赞 0条评论

一、备份服务 (rsync方式)

1、服务端(server)为windows

(1)使用方式:rsync同步服务,需要安装server端,安装软件,cwRsyncServer_4.1.0_Installer

(2) 在windows创建rsync用户,并设置密码

(3) 配置配置文件rsyncdserver.conf

use chroot = false
strict modes = false
hosts allow = *
log file = rsyncd.log
pid file = rsyncd.pid
uid = 0
gid = 0

[backup]
path = /cygdrive/e/BigDatabackup  ###e盘BigDatabackup目录
comment = backup
ignore errors
read only = no
list = no
host allow = 172.18.0.0/16        ###允许访问的IP段
auth users = rsync
secrets file = rsyncd.password    ###客户端使用服务端的用户rsync的密码文件
transfer logging = yes

[sapbackup]
path = /cygdrive/d/sapbackup
comment = sapbackup
ignore errors
read only = no
list = no
host allow = 172.18.0.0/16
auth users = rsync
secrets file = rsyncd.password
transfer logging = yes

[ncoabackup]
path = /cygdrive/d/ncoabackup
comment = ncoabackup
ignore errors
read only = no
list = no
host allow = 172.18.0.0/16
auth users = rsync
secrets file = rsyncd.password
transfer logging = yes

2、客户端(client)为linux

    (1)安装rsync软件

    (2)配置密码文件:

 

[root@YCZBNCPOAP BACKUP]# ll /etc/rsyncd.password

-rw-------. 1 root root 18 12月 10 2018 /etc/rsyncd.password

内容:为服务端rsync用户的密码

(3)脚本:

[root@YCZBNCPOAP BACKUP]# cat /home/Scripts/rsync.sh 
#!/bin/bash  
a="rsync -avzt /home/BACKUP/ rsync@172.18.1.115::ncoabackup/ --ignore-existing --password-file=/etc/rsyncd.password >> /home/Scripts/rsync.log"
eval $a

    (4)做定时任务:crontab -e

    00 06 * * * sh /home/Scripts/rsync.sh >>/dev/null

3、客户端(client) windows

 

C:
cd c:\ICW\bin
rsync -avPz /cygdrive/e/RMAN rsync@172.18.1.115::backup/MDM_172.18.1.70 <passwd.txt

 

二、数据库备份脚本(LINUX)——NC/OA/SRM/EP等

1、NC/OA数据库脚本(EXPDP):

    (1)expdp_jpg.sh

#!/bin/sh
su  - oracle -c 'expdp YCZBNZ/Yczbjtnz1qaz#EDC@127.0.0.1/orcl  schemas=YCZBNZ directory=DUMP_JPG  dumpfile=JPG_`date +%Y%m%d\%H%M%S`_expdp.dmp logfile=JPG_`date +%Y%m%d\%H%M%S`_expdp.log compression=all'
####runuser - oracle -c 'exp YCZBNZ/Yczbjtnz1qaz#EDC@orcl file=/home/JPGBACKUP/JPG_`date +%Y%m%d`.dmp log=/home/JPGBACKUP/JPG_`date +%Y%m%d`.log owner=YCZBNZ'
delcatalog="/home/BACKUP/JPGBACKUP/JPG_*"
find $delcatalog -mtime +7 -type f|xargs rm -f

    (2)expdp_jpg.sh

 

#!/bin/sh
su  - oracle -c 'expdp YCZBWZ/yczb1qaz#EDC@127.0.0.1/orcl  schemas=YCZBWZ directory=DUMP_YCZBNC  dumpfile=YCZBNC_`date +%Y%m%d\%H%M%S`_expdp.dmp logfile=YCZBNC_`date +%Y%m%d\%H%M%S`_expdp.log compression = all'
#runuser - oracle -c 'exp YCZBWZ/1qaz#EDC@orcl file=/home/NCBACKUP/YCZBNC_`date +%Y%m%d`.dmp log=/home/NCBACKUP/YCZBNC_`date +%Y%m%d`.log owner=YCZBWZ'
delcatalog="/home/BACKUP/NCBACKUP/YCZBNC_*"
find $delcatalog -mtime +7 -type f|xargs rm -f

    (3) expdp_OA.sh

#!/bin/sh
su  - oracle -c 'expdp yczboa/yczbjt@oraecology  schemas=yczboa directory=DUMP_OA  dumpfile=OA_8_0_2_`date +%Y%m%d%\H%M%S`_expdp.dmp logfile=OA_8_0_2_`date +%Y%m%d\%H%M%S`_expdp.log compression=all'
TZ=TZ+48
delcatalog="/home/BACKUP/OABACKUP/OA_8_0_2*"
find $delcatalog -mtime +10 -type f|xargs rm -f
#rm -rf /home/OABACKUP/OA_8_0_`date +%Y%m%d`.dmpdp
#rm -rf /backup2/OAbak/OA_8_0_`date +%Y%m%d`.dmpdp
#rm -rf /backup2/OAbak/OA_8_0_`date +%Y%m%d`.log

    2、NC/OA数据库脚本(RMAN):

    (1)RMAN_NC_backup_level_0.sh

[root@YCZBNCPOAP Scripts]# cat rman_NC_backup_level_0.sh 
#!/bin/bash
su - oracle -c "
export ORACLE_SID=orcl
rman target /  log=/home/Scripts/rman_level_0.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;

backup as compressed backupset incremental level 0 format '/home/BACKUP/RMANBAK/db_level0_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/home/BACKUP/RMANBAK/arch_%d_%I_%T_%s_%p_%c.bak';

backup current controlfile format '/home/BACKUP/RMANBAK/control_%d_%I_%T_%s.bak';
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/home/BACKUP/RMANBAK/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-7';
}
EOF
"

##delete n days ago backup's file;--LLL-2019-10-31

del_backup_file="/home/BACKUP/RMANBAK/*"
find $del_backup_file -mtime +7 -type f|xargs rm -f

    (2)RMAN_NC_backup_level_1.sh

#!/bin/bash
su - oracle -c "
export ORACLE_SID=orcl
rman target /  log=/home/Scripts/rman_level_1.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 1 format '/home/BACKUP/RMANBAK/db_level1_%d_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/home/BACKUP/RMANBAK/arch_%d_%I_%T_%s_%p_%c.bak';

backup current controlfile format '/home/BACKUP/RMANBAK/control_%d_%I_%T_%s.bak';
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/home/BACKUP/RMANBAK/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-7';
}
EOF
"
##delete n days ago backup's file;--LLL-2019-10-31

del_backup_file="/home/BACKUP/RMANBAK/*"
find $del_backup_file -mtime +7 -type f|xargs rm -f

 

    (3)RMAN_OA_backup_level_0.sh

[root@YCZBNCPOAP Scripts]# cat rman_NC_backup_level_0.sh 
#!/bin/bash
su - oracle -c "
export ORACLE_SID=oraecology 
rman target /  log=/home/Scripts/rman_level_0.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 0 format '/home/BACKUP/RMANBAK_OA/db_level0_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/home/BACKUP/RMANBAK_OA/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/home/BACKUP/RMANBAK_OA/control_%d_%I_%T_%s.bak';
backup spfile format '/home/BACKUP/RMANBAK_OA/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/home/BACKUP/RMANBAK/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-7';
}
EOF
"
##delete n days ago backup's file;--LLL-2019-10-31

del_backup_file="/home/BACKUP/RMANBAK/*"
find $del_backup_file -mtime +7 -type f|xargs rm -f

    (4)RMAN_OA_backup_level_1.sh

#!/bin/bash
su - oraecology -c "
export ORACLE_SID=oraecology 
rman target /  log=/home/Scripts/rman_level_1.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 1 format '/home/BACKUP/RMANBAK_OA/db_level1_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/home/BACKUP/RMANBAK_OA/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/home/BACKUP/RMANBAK_OA/control_%d_%I_%T_%s.bak';
backup spfile format '/home/BACKUP/RMANBAK_OA/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/home/BACKUP/RMANBAK_OA/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-7';
}
EOF
"
##delete n days ago backup's file;--LLL-2019-10-31

del_backup_file="/home/BACKUP/RMANBAK/*"
find $del_backup_file -mtime +7 -type f|xargs rm -f

(5)异机传输备份脚本:

#!/bin/bash  
a="rsync -avzt /home/BACKUP/ rsync@172.18.1.115::ncoabackup/ --ignore-existing --password-file=/etc/rsyncd.password >> /home/Scripts/rsync.log"
eval $a

(6)上述任务定时执行:

30 01 * * * sh /home/Scripts/expdp_jpg.sh
30 02 * * * sh /home/Scripts/expdp_yczbnc.sh
30 00 * * * sh /home/Scripts/expdp_OA.sh
00 04 * * 7 sh /home/Scripts/rman_NC_backup_level_0.sh >>/dev/null
00 04 * * 1-6 sh /home/Scripts/rman_NC_backup_level_1.sh >>/dev/null
00 06 * * * sh /home/Scripts/rsync.sh >>/dev/null

 

3、SAP 数据库脚本(RMAN):

(1) SRMD——rman_backup_level_0.sh (0级备份)

#!/bin/bash
###LLL-2019-10-10
su - oracle -c "
rman target /  log=/scripts/rman_level_0.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 0 format '/databackup/rmanbak/db_level0_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/databackup/rmanbak/control_%d_%I_%T_%s.bak'; 
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-2';
}
EOF
"
##delete n days ago backup's file;--LLL-2019-10-31

del_backup_file="/databackup/rmanbak/*"
find $del_backup_file -mtime +7 -type f|xargs rm -f

(2)SRMD——rman_backup_level_1.sh (1级备份)

#!/bin/bash
###LLL-2019-10-10
su - oracle -c "
rman target /  log=/scripts/rman_level_1.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 1 format '/databackup/rmanbak/db_level1_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/databackup/rmanbak/control_%d_%I_%T_%s.bak'; 
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-2';
}
EOF
"
##delete n days ago backup's file;--LLL-2019-10-31

del_backup_file="/databackup/rmanbak/*"
find $del_backup_file -mtime +7 -type f|xargs rm -f

(3)SRMQ——rman_backup_level_0.sh (0级备份)

#!/bin/bash
###LLL-2019-10-10
su - orasrq -c "
rman target /  log=/scripts/rman_level_0.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 0 format '/databackup/rmanbak/db_level0_%d_%I_%T_%s.bak' database;

backup as compressed backupset archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/databackup/rmanbak/control_%d_%I_%T_%s.bak'; 
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-2';
}
EOF
"

(4)SRMQ——rman_backup_level_1.sh (0级备份)

SRMQAS:/scripts # cat rman_backup_level_1.sh 
#!/bin/bash
###LLL-2019-10-10
su - orasrq -c "
rman target /  log=/scripts/rman_level_1.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 1 format '/databackup/rmanbak/db_level1_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/databackup/rmanbak/control_%d__%I%T_%s.bak';
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak';  
#backup archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-2';
}
EOF
"

(5)SRMP——rman_backup_level_0.sh (0级备份)

#!/bin/bash
su - orasrp -c "
rman target /  log=/scripts/rman_level_0.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 0 format '/databackup/rmanbak/db_level0_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/databackup/rmanbak/control_%d_%I_%T_%s.bak'; 
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-2';
}
EOF
"

(6)SRMP——rman_backup_level_1.sh (1级备份)

 

#!/bin/bash
su - orasrp -c "
rman target /  log=/scripts/rman_level_1.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 1 format '/databackup/rmanbak/db_level1_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/databackup/rmanbak/control_%d_%I_%T_%s.bak'; 
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-2';
}
EOF
"

(7)异机传输备份脚本:

SRD

#!/bin/bash  
a="rsync -avzt /databackup/ rsync@172.18.1.115::sapbackup/SRM_DEV_172.18.1.32 --ignore-existing --password-file=/etc/rsyncd.password >> /scripts/rsync.log"
eval $a

/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \db_level0* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \db_level1* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \arch* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \control* | xargs rm -f

 

SRQ

#!/bin/bash  
##LLL-2019-10-11
a="rsync -avzt /databackup/ rsync@172.18.1.115::sapbackup/SRM_QAS_172.18.1.33 --ignore-existing --password-file=/etc/rsyncd.password >> /scripts/rsync.log"
eval $a
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \db_level0* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \db_level1* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \arch* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \control* | xargs rm -f

SRP

#!/bin/bash  
##LLL-2019-10-11
a="rsync -avzt /databackup/ rsync@172.18.1.115::sapbackup/SRM_PRD_172.18.1.16 --ignore-existing --password-file=/etc/rsyncd.password >> /scripts/rsync.log"
eval $a
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \db_level0* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \db_level1* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \arch* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \control* | xargs rm -f

(8)上述任务定时执行:crontab -l

# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.ky896Z installed on Fri Oct 11 15:01:06 2019)
# (Cronie version 4.2)
#00 01 * * * sh /scripts/oracle_archivelog_del.sh  >>/scripts/archlog_del.log
#zabbix_oracle wangxuejin 2019-08-31
*/5 * * * * su - orasrp  /home/orasrp/tablespace_check.sh
00 02 * * 1-6 sh /scripts/rman_backup_level_1.sh >>/dev/null
00 02 * * 7 sh /scripts/rman_backup_level_0.sh >>/dev/null
00 05 * * * sh /scripts/rsync.sh >>/dev/null

4、EP----PORTAL数据库脚本(RMAN):

(1) EPD——rman_backup_level_0.sh (0级备份)

 

#!/bin/bash
###LLL-2019-10-16
su - oracle -c "
rman target /  log=/scripts/rman_level_0.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 0 format '/databackup/rmanbak/db_level0_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/databackup/rmanbak/control_%d_%I_%T_%s.bak'; 
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-2';
}
EOF
"

(2) EPD——rman_backup_level_1.sh (1级备份)

#!/bin/bash
###LLL-2019-10-16
su - oracle -c "
rman target /  log=/scripts/rman_level_1.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 1 format '/databackup/rmanbak/db_level1_%d_%I_%T_%s.bak' database;

backup as compressed backupset archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/databackup/rmanbak/control_%d_%I_%T_%s.bak'; 
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-2';
}
EOF
"

(3)EPQ——rman_backup_level_0.sh (0级备份)

#!/bin/bash
###LLL-2019-10-16
su - oracle -c "
rman target /  log=/scripts/rman_level_0.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 0 format '/databackup/rmanbak/db_level0_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/databackup/rmanbak/control_%d_%I_%T_%s.bak';
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak';  
#backup archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-2';
}
EOF
"

(4)EPQ——rman_backup_level_1.sh (1级备份)

#!/bin/bash
###LLL-2019-10-16
su - oracle -c "
rman target /  log=/scripts/rman_level_1.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 1 format '/databackup/rmanbak/db_level1_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/databackup/rmanbak/control_%d_%I_%T_%s.bak'; 
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-2';
}
EOF
"

(5)EPP——rman_backup_level_0.sh (0级备份)

#!/bin/bash
###LLL-2019-10-16
su - oraepp -c "
rman target /  log=/scripts/rman_level_0.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 0 format '/databackup/rmanbak/db_level0_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/databackup/rmanbak/control_%d_%I_%T_%s.bak'; 
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-2';
}
EOF
"

(6)EPP——rman_backup_level_1.sh (1级备份)

#!/bin/bash
###LLL-2019-10-16
su - oraepp -c "
rman target /  log=/scripts/rman_level_1.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 1 format '/databackup/rmanbak/db_level1_%d_%I_%T_%s.bak' database;
backup  as  compressed  backupset  archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/databackup/rmanbak/control_%d_%I_%T_%s.bak'; 
backup spfile format '/databackup/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/databackup/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-2';
}
EOF
"
##delete n days ago backup's file;--LLL-2019-10-31

del_backup_file="/databackup/rmanbak/*"
find $del_backup_file -mtime +7 -type f|xargs rm -f

(7)异机传输备份脚本:

EPD:

#!/bin/bash  
a="rsync -avzt /databackup/ rsync@172.18.1.115::sapbackup/EP_DEV_172.18.1.72 --ignore-existing --password-file=/etc/rsyncd.password >> /scripts/rsync.log"
eval $a
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \db_level0* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \db_level1* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \arch* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \control* | xargs rm -f

 

EPQ:

 

#!/bin/bash  
a="rsync -avzt /databackup/ rsync@172.18.1.115::sapbackup/EP_QAS_172.18.1.74 --ignore-existing --password-file=/etc/rsyncd.password >> /scripts/rsync.log"
eval $a
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \db_level0* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \db_level1* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \arch* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \control* | xargs rm -f

EPP:

 

#!/bin/bash  
a="rsync -avzt /databackup/ rsync@172.18.1.115::sapbackup/EP_PRD_172.18.1.76 --ignore-existing --password-file=/etc/rsyncd.password >> /scripts/rsync.log"
eval $a
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \db_level0* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \db_level1* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \arch* | xargs rm -f
/bin/find  /databackup/rmanbak/ -mtime +7 -type f -name \control* | xargs rm -f

(8)上述任务定时执行:crontab -l

 

EPDEV:/scripts # crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.ZebJOL installed on Tue Oct 15 15:12:02 2019)
# (Cronie version 4.2)
#00 01 * * * sh /scripts/oracle_archivelog_del.sh  >>/scripts/archlog_del.log
00 02 * * 1-6 sh /scripts/rman_backup_level_1.sh >>/dev/null
00 02 * * 7 sh /scripts/rman_backup_level_0.sh >>/dev/null
30 04 * * * sh /scripts/rsync.sh >>/dev/null

 

三、数据库备份脚本(Windows)——MDM

    0级备份

1、运行脚本:rman_excute_level_0.bat

rman target / nocatalog CMDFILE 'E:/RMAN/rman_backup_level_0.txt' LOG 'E:/RMAN/rman_backup_%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%".log'

2、备份脚本:rman_backup_level_0.txt

run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 0 format 'E:\RMAN\db_level0_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format'E:\RMAN\arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format 'E:\RMAN\control_%d_%I_%T_%s.bak'; 
backup spfile format 'E:\RMAN\Spfile_%d_%I_%T_%s_%p_%c.bak'; 

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-5';
}

    1级备份

 

3、运行脚本:rman_excute_level_1.bat

rman target / nocatalog CMDFILE 'E:/RMAN/rman_backup_level_1.txt' LOG 'E:/RMAN/rman_backup_%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%".log'

4、备份脚本:rman_backup_level_1.txt

run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 1 format 'E:\RMAN\db_level1_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format 'E:\RMAN\arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format 'E:\RMAN\control_%d_%I_%T_%s.bak'; 
backup spfile format 'E:\RMAN\Spfile_%d_%I_%T_%s_%p_%c.bak'; 

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-5';
}

5、异机传输备份脚本:rsync.bat

C:
cd c:\ICW\bin
rsync -avPz /cygdrive/e/RMAN rsync@172.18.1.115::backup/MDM_172.18.1.70 <passwd.txt

 

 

Windows下的过期文件删除脚本(172.18.1.115)

@echo on
forfiles -p "D:\NCOABACKUP\JPGBACKUP" -s  -d -7 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles -p "D:\NCOABACKUP\NCBACKUP" -s  -d -7 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles -p "D:\NCOABACKUP\OABACKUP" -s  -d -7 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles -p "E:\BigDatabackup\svn_172.18.1.204\everyday" -s  -d -3 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles -p "E:\BigDatabackup\svn_172.18.1.204\sunday" -s  -d -21 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles -p "E:\BigDatabackup\svn_172.18.1.204\month\month_tar_svn" -s  -d -31 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles -p "E:\BigDatabackup\MDM_172.18.1.70\DATABACKUP" -s  -d -7 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles  -p  "E:\BigDatabackup\MDM_172.18.1.70\RMAN" -s  -d -7 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles -p "D:\NCOABACKUP\SRM_DEV_172.18.1.32\rmanbak" -s  -d -7 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles -p "D:\NCOABACKUP\SRM_QAS_172.18.1.33\rmanbak" -s  -d -7 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles -p "D:\NCOABACKUP\SRM_PRD_172.18.1.16\rmanbak" -s  -d -7 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles -p "D:\SAPBACKUP\EP_DEV_172.18.1.72\rmanbak" -s  -d -7 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles -p "D:\SAPBACKUP\EP_QAS_172.18.1.74\rmanbak" -s  -d -7 -c "cmd /c del @path" >>D:\wxj_bat\del.log
forfiles -p "D:\SAPBACKUP\EP_PRD_172.18.1.76\rmanbak" -s  -d -7 -c "cmd /c del @path" >>D:\wxj_bat\del.log

 

五、昆山塑业正式机脚本(RMAN)

 

1、rman_backup_level_0.sh (0级备份)

#!/bin/bash
###LLL-2020-02-27
su - oracle -c "
rman target /  log=/scripts/rman_level_0.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 0 format '/data/rmanbak/db_level0_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/data/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/data/rmanbak/control_%d_%I_%T_%s.bak'; 
backup spfile format '/data/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/data/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-3';
}
EOF
"
##delete n days ago backup's file;--LLL-2019-10-31

del_backup_file="/data/rmanbak/*"
find $del_backup_file -mtime +7 -type f|xargs rm -f

(6)rman_backup_level_1.sh (1级备份)

#!/bin/bash
###LLL-2020-02-27
su - oracle -c "
rman target /  log=/scripts/rman_level_1.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 1 format '/data/rmanbak/db_level1_%d_%I_%T_%s.bak' database;
backup  as  compressed  backupset  archivelog all format '/data/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/data/rmanbak/control_%d_%I_%T_%s.bak'; 
backup spfile format '/data/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak'; 
#backup archivelog all format '/data/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-3';
}
EOF
"
##delete n days ago backup's file;--LLL-2019-10-31

del_backup_file="/data/rmanbak/*"
find $del_backup_file -mtime +7 -type f|xargs rm -f

 

异机传输:

#!/bin/bash
# name: mesBACKUP 
# date: 20200413
# user:LLL

DIR=/data/rmanbak
rsync -az --ignore-existing /data/rmanbak/*  rsync@172.18.1.115::KSSYMesbackup/ --password-file=/etc/rsyncd.password  >> /data/rmanbak/rsync.log

上述任务定时执行:crontab -l

[root@localhost ~]# crontab -l
00 02 * * 1-6 sh /data/scripts/rman_backup_level_1.sh >>/dev/null
00 02 * * 7 sh /data/scripts/rman_backup_level_0.sh >>/dev/null
00 03 * * * sh /data/scripts/rsync_MESBACKUP.sh >>/dev/null

六、上海一厂正式机脚本(EXPDP)

 expdp_shycbzmes_everyday_full.sh

#!/bin/sh
su  - oracle -c 'expdp system/Yczbjtshyc190411  DIRECTORY=backup_mes DUMPFILE=SHYCBZMES_`date +%Y%m%d%\H%M%S`_FULL_expdp.dmpdp  logfile=SHYCBZMES_`date +%Y%m%d\%H%M%S`_FULL_expdp.log full=y compression=all'
TZ=TZ+48
delcatalog="/data/backup/SHYCBZMES*"
find $delcatalog -mtime +14 -type f|xargs rm -f

 

七、上海一厂正式机脚本(RMAN)

1、rman_backup_level_0.sh (0级备份)

#!/bin/bash
###LLL-2020-04-11
su - oracle -c "
rman target /  log=/data/scripts/rman_level_0.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 0 format '/data/rmanbak/db_level0_%d_%I_%T_%s.bak' database;
backup as compressed backupset archivelog all format '/data/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/data/rmanbak/control_%d_%I_%T_%s.bak';
backup spfile format '/data/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak';
#backup archivelog all format '/data/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
#delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-7';
}
EOF
"
##delete n days ago backup's file;--LLL-2019-10-31

del_backup_file="/data/rmanbak/*"
find $del_backup_file -mtime +14 -type f|xargs rm -f

(6)rman_backup_level_1.sh (1级备份)

#!/bin/bash
###LLL-2020-04-11
su - oracle -c "
rman target /  log=/data/scripts/rman_level_1.log<<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup as compressed backupset incremental level 1 format '/data/rmanbak/db_level1_%d_%I_%T_%s.bak' database;
backup  as  compressed  backupset  archivelog all format '/data/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak';
backup current controlfile format '/data/rmanbak/control_%d_%I_%T_%s.bak';
backup spfile format '/data/rmanbak/Spfile_%d_%I_%T_%s_%p_%c.bak';
#backup archivelog all format '/data/rmanbak/arch_%d_%I_%T_%s_%p_%c.bak' delete input ;

release channel c1;
release channel c2;
release channel c3;
release channel c4;
crosscheck backup;
crosscheck archivelog all;
#delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
delete force noprompt archivelog until time 'sysdate-7';
}
EOF
"

##delete n days ago backup's file;--LLL-2020-02-27

del_backup_file="/data/rmanbak/*"
find $del_backup_file -mtime +14 -type f|xargs rm -f

异机传输:

[root@localhost ~]# cat /data/scripts/rsync_MESBACKUP.sh 
#!/bin/bash
# name: mesBACKUP 
# date: 20200413
# user:LLL

DIR=/data/rmanbak
rsync -az --ignore-existing /data/rmanbak/*  rsync@172.18.1.115::shycbackup/SHYCBZMES --password-file=/etc/rsyncd.password  >> /data/rmanbak/rsync.log

上述任务定时执行:crontab -l

[root@localhost rmanbak]# crontab -l
00 02 * * * sh /data/scrpits/expdp_shycbzmes_everyday_full.sh 
00 04 * * 1-6 sh /data/scripts/rman_backup_level_1.sh >>/dev/null
00 04 * * 7 sh /data/scripts/rman_backup_level_0.sh >>/dev/null
00 05 * * * sh /data/scripts/rsync_MESBACKUP.sh >>/dev/null

 

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2022年3月10日

admin

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

您需要 登录 之后才可以评论

COPYRIGHT © 2022 拓扑园. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

鲁ICP备2021020523号

鲁ICP备2021020523号