欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

rman_oracle数据库备份脚本整理

程序员文章站 2022-05-08 09:29:44
1、Linux-rman-backup1.1 开启归档日志 SQL> SHUTDOWN IMMEDIATE; SQL> STARTUP MOUNT; mkdir -p /u01/arch SQL> alter system set log_archive_dest_1='location=/u01/arch'; SQL> alter database archivelog; SQL> alter database open;......

1、Linux-rman-backup

1.1 开启归档日志

    SQL> SHUTDOWN IMMEDIATE;
    SQL> STARTUP MOUNT;
    mkdir -p /u01/arch
    SQL> alter system set log_archive_dest_1='location=/u01/arch';
    SQL> alter database archivelog;
    SQL> alter database open;
    SQL> archive log list;

1.1 一级备份(每天一次)

cat bak0.sh

#!/bin/bash
source ~/.bash_profile
/u01/oracle/product/11.2.0/db_1/bin/rman target / nocatalog log /orabak/logs/bak0_`date +%Y%m%d`.log  <<EOF
run{
crosscheck backup;
crosscheck archivelog all;
delete expired archivelog all;
allocate channel c1 device type disk;
backup as compressed backupset database format '/orabak/db0_%d_%T_%U.bak' plus archivelog format '/orabak/ar0_%d_%T_%U.bak';
backup current controlfile format '/orabak/control0_%d_%T_%U.bak';
report obsolete device type disk;
delete noprompt obsolete device type disk;
delete noprompt expired backup device type disk;
delete archivelog all completed before 'sysdate - 1';
release channel c1; 
}
EOF
exit

1.2 二级备份(每周一次)

cat bak1.sh

#!/bin/bash
source ~/.bash_profile
/u01/oracle/product/11.2.0/db_1/bin/rman target / nocatalog log /orabak/logs/bak1_`date +%Y%m%d`.log  <<EOF
run{
crosscheck backup;
delete obsolete;
crosscheck archivelog all;
delete expired archivelog all;
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
allocate channel c5 device type disk;
allocate channel c6 device type disk;
allocate channel c7 device type disk;
allocate channel c8 device type disk;
backup as compressed backupset incremental level 1 database format '/orabak/db1_%d_%T_%U.bak';
sql 'alter system archive log current';  
backup as compressed backupset archivelog all format '/orabak/ar1_%d_%T_%U.bak'  delete all input;
backup current controlfile format '/orabak/control1_%d_%T_%U.bak';
report obsolete device type disk;
delete noprompt obsolete device type disk;
delete archivelog all completed before 'sysdate - 1';
delete noprompt expired backup device type disk;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
release channel c8;
}
EOF
exit

1.3 定时任务

crontab -e

00 23  * * *  sh bak0.sh

00 23  * * 0  sh bak1.sh

2.win-rman-backup

2.1 开启归档日志

    SQL> SHUTDOWN IMMEDIATE;
    SQL> STARTUP MOUNT;
    SQL> alter system set log_archive_dest_1='location=E:\arch';
    SQL> alter database archivelog;
    SQL> alter database open;
    SQL> archive log list;

2.1 一级备份(每天一次)

cat bat0.bat

rman target SYSTEM/******@SID cmdfile 'E:\servers\bak01.txt' log 'E:\orabak\logs\bak0_`date +%Y%m%d`.log'

cat bat01.txt

run{
crosscheck backup;
crosscheck archivelog all;
delete expired archivelog all;
allocate channel c1 device type disk;
backup as compressed backupset database format 'E:\orabak\db0_%d_%T_%U.bak' plus archivelog format 'E:\orabak\ar0_%d_%T_%U.bak';
backup current controlfile format 'E:\orabak\control0_%d_%T_%U.bak';
report obsolete device type disk;
delete noprompt obsolete device type disk;
delete noprompt expired backup device type disk;
delete archivelog all completed before 'sysdate - 1';
release channel c1; 
}
exit

2.2 二级备份(每周一次)

cat bak1.bat

rman target SYSTEM/******@SID cmdfile 'E:\servers\bak11.txt' log 'E:\orabak\logs\bak1_`date +%Y%m%d`.log'
cat bak11.bat

run{
crosscheck backup;
delete obsolete;
crosscheck archivelog all;
delete expired archivelog all;
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
allocate channel c5 device type disk;
allocate channel c6 device type disk;
allocate channel c7 device type disk;
allocate channel c8 device type disk;
backup as compressed backupset incremental level 1 database format 'E:\orabak\db1_%d_%T_%U.bak';
sql 'alter system archive log current';  
backup as compressed backupset archivelog all format 'E:\orabak\ar1_%d_%T_%U.bak'  delete all input;
backup current controlfile format 'E:\orabak\control1_%d_%T_%U.bak';
report obsolete device type disk;
delete noprompt obsolete device type disk;
delete archivelog all completed before 'sysdate - 1';
delete noprompt expired backup device type disk;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
release channel c8;
}
exit

2.3 定时任务

在cmd下输入taskschd.msc---》右击任务计划程序库,创建基本任务逐步操作,然后根据提示操作即可!

 

注:该备份脚本仅用于自己操作,大佬们如果用,可做参考,出现问题,概不负责!

本文地址:https://blog.csdn.net/weixin_41761624/article/details/108979915

相关标签: Linux 数据库