通过oracle任务计划定期备份数据库
之前涉及到oracle定期备份的问题走的都是操作系统层面的任务计划,下面用oracle的taskscheduler定期执行oracle的备份,详细步骤见下:1备份语句/oracle/bak/full
之前涉及到oracle定期备份的问题走的都是操作系统层面的任务计划,下面用oracle的task scheduler 定期执行oracle的备份,详细步骤见下:
1 备份语句/oracle/bak/fullbk.txt如下:
[oracle@dest ~]$ cat /oracle/bak/fullbk.txt
run{
delete noprompt obsolete; # 以不提示的方式删除状态为obsolete的备份(注意备份是否obsolete和备份保留策略有关)
crosscheck backup; # 校验rman资料库中记录的备份是否存在于磁盘或物理设备上,如果不存在,,则更改rman资料库中该备份记录为expired状态
delete noprompt expired backup; # 以不提示的方式删除rman资料库中所有标记为expired状态的记录
crosscheck archivelog all; # 校验rman资料库中所有归档记录,对在物理设备上不存在的归档,在rman资料库中更新其标记为expired
delete noprompt expired archivelog all; #以不提示的方式删除rman资料库中所有标记为expired状态的归档记录
backup incremental level=0 database format '/backup/crm/full-%T-%U.bak'; #做一个0级别的数据库全备份
backup archivelog all format '/backup/crm/arch-%T-%U.bak'; #备份所有归档
backup current controlfile format '/backup/crm/ctl-%T-%U.bak'; #备份当前控制文件
backup spfile format '/backup/crm/spf-%T-%U.bak'; # 备份参数文件
delete noprompt archivelog all completed before 'SYSDATE - 7'; # 以不提示的方式删除7天之前的所有归档
}
注意 以上脚本仅仅是为测试,该脚本对于从上一次全备份到数据库当前状态丢失了一部分归档,或者归档损坏的情况,是无法进行完全恢复的。
2 备份脚本/oracle/bak/rman.sh如下:
[oracle@dest ~]$ cat /oracle/bak/rman.sh
#!/bin/bash
export today=`date +%Y%m%d%H%M`
export ORACLE_HOME=/oracle/app/db1
export ORACLE_SID=CRM
$ORACLE_HOME/bin/rman target sys/DHHZDHHZ log=/oracle/bak/crm.log cmdfile=/oracle/bak/fullbk.txt
mv /oracle/bak/crm.log "/oracle/bak/crm${today}.log"
此脚本让rman调用/oracle/bak/fullbk.txt文本中的备份语句,记录当前备份过程于日志文件,并更改生成的日志文件名为当前日期。
3 在oracle中创建program
begin
dbms_scheduler.create_program (
program_name =>'oracle_bk_program',
program_action =>'/oracle/bak/rman.sh',
program_type =>'EXECUTABLE',
enabled =>true,
comments =>'oracle.sh');
end;
/
查询我们刚刚创建的program如下
select program_name,program_type,program_action,number_of_arguments,enabled from user_scheduler_programs where program_name='ORACLE_BK_PROGRAM';
PROGRAM_NAME PROGRAM_TYPE PROGRAM_ACTION NUMBER_OF_ARGUMENTS ENABL
------------------- ---------------- ---------------------- ------------------- -----
ORACLE_BK_PROGRAM EXECUTABLE /oracle/bak/rman.sh 0 TRUE
注意如果要修改程序,job或者shceduler则可用如下语句
BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE (
name => '',
attribute => '',
value => '');
END;
/
如下:
BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE (
name => 'oracle_bk_schedule',
attribute => 'repeat_interval',
value => 'FREQ=DAILY;BYHOUR=15,16,17');
END;
/
4 创建一个scheduler
begin
dbms_scheduler.create_schedule(
schedule_name =>'oracle_bk_schedule',
repeat_interval =>'FREQ=DAILY;BYHOUR=15,16,17',
comments =>'backup start 3pm');
end;
/
查选我们刚刚创建的scheduler如下:
SQL> select schedule_name,repeat_interval from user_scheduler_schedules where schedule_name='ORACLE_BK_SCHEDULE';
SCHEDULE_NAME REPEAT_INTERVAL
------------------------------ ------------------------------------------------------------
ORACLE_BK_SCHEDULE FREQ=DAILY;BYHOUR=17
5 创建一个job,在job中引用创建的程序和scheduler

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

MongoDB is suitable for unstructured data and high scalability requirements, while Oracle is suitable for scenarios that require strict data consistency. 1.MongoDB flexibly stores data in different structures, suitable for social media and the Internet of Things. 2. Oracle structured data model ensures data integrity and is suitable for financial transactions. 3.MongoDB scales horizontally through shards, and Oracle scales vertically through RAC. 4.MongoDB has low maintenance costs, while Oracle has high maintenance costs but is fully supported.

Analysis of memory leak phenomenon of Java programs on different architecture CPUs. This article will discuss a case where a Java program exhibits different memory behaviors on ARM and x86 architecture CPUs...

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

The troubleshooting idea of SSH connection failure after SpringBoot service has been running for a period of time has recently encountered a problem: a Spring...

DMA in C refers to DirectMemoryAccess, a direct memory access technology, allowing hardware devices to directly transmit data to memory without CPU intervention. 1) DMA operation is highly dependent on hardware devices and drivers, and the implementation method varies from system to system. 2) Direct access to memory may bring security risks, and the correctness and security of the code must be ensured. 3) DMA can improve performance, but improper use may lead to degradation of system performance. Through practice and learning, we can master the skills of using DMA and maximize its effectiveness in scenarios such as high-speed data transmission and real-time signal processing.
