Timed backup to Oracle database by using crontab

xiaoxiao2021-03-06  46

Using crontab to implement Timers of Oracle Database 01-4-29 at 09:53:52

Timed hot backup (EXP) for Oracle Databases is usually implemented in two ways, one is to implement the task queue manager (Job Queue) provided in the Oracle database; the other is the timing execution command using the operating system To be done. In the first method, the database is required to start the background process SNP, and the startup parameters of the task queue must be added in the Oracle's initialization file, and the second method does not need to make any changes to the database. This example describes how to complete the hot backup of the Oracle8i database using the timing trigger crontab under Digital Unix 4.0F.

First, the method of use of the command

1, Crontab usage

Crontab is a timing task trigger under UNIX system, and its user's permissions are recorded in the following two files:

/usr/var/adm/cron/cron.deny: The user listed in this file does not allow the crontab command;

/usr/var/adm/cron/cron.allow: The user listed in this file allows the crontab command;

The format of the crontab command is: crontab -l | -v | -r | -e [username], its parameter meanings, such as Table 1:

Table 1 method of use of crontab parameters

parameter name

meaning

-L

Display the content of the user's crontab file

-V

Display the content of the user's crontab file and its submitted time, only for the Compaq series

-r

Remove the user's crontab file from the crontab directory

-e

Edit user's crontab file

The CRONTAB file established by the user is stored in / var / spool / cron / crontabs, and its file name is consistent with the username. Its format is divided into six segments, the first five sections are time setting segments, and the sixth paragraph is the command segment of the required execution, the format is as follows:

* * * * *

The meaning of its time period is as follows:

Mean of time segment in the Tern crontab file

segment

meaning

Ranges

First paragraph

Minute

0-59

Second paragraph

Mean

0-23

Third paragraph

Representative date

1-31

Paragraph 4

Representative month

1-12

Fifth paragraph

Representing the day of the week, 0 represents Sunday

0-6

Example: If the content of the user's crontab file is: 29 19 * * * Echo ITS DINNER TIME, the system is displayed daily 19:29 on the 'ITS DINNER TIME'.

2, use method of exp

EXP is the thermal backup command of the Oracle database, which is often used in the format:

Exp userid file = ... Owner = [username]

Because the parameters of the EXP command are introduced, the reader can understand the usage of the EXP commands through the Exp Help = y command. The following will introduce the meaning of the three parameters to be used to everyone, see Table 3 :

Common parameters of Table three EXP

parameter name

meaning

UserID

Writing is [username] / [userpassword], username / password in Oracle, it must be the first parameter of EXP

File

Backup file location and name

Owner

Back up the Oracle object owned by the user (table, stored procedure, etc.)

Second, implementation

Suppose the owner of the database is Oracle, the user of the database is Scott, whose password is TRIGGER, the ORACLE Database parameter $ Oracle_Home is / usr / oracle, $ ORACLE_SID is ORCL, the implementation steps are as follows: 1. Establish the shell for the backup

Use the vi command in / usr / oracle to create file backup.sh, its contents:

Oracle_home = / usr / oracle;

Export Oracle_home;

Oracle_sid = Orcl;

Export oracle_sid;

/ usr / oracle / bin / exp scott / trigger file = / usr / oracle / backup.dmp oer = scott

Modify the properties of Backup.sh using the chmod command to execute:

CHMOD X backup.sh

At this point, an executable backup.sh has a backup function has been built. Its execution is to back up the Oracle object owned by Scott into the backup.dmp in / usr / oracle, and the reader can run it directly to see the effect. It is worth noting that the two environmental parameters of Oracle in Backup.SH must declare that the system will report an error. The next step will begin to establish the CRONTAB file of the Oracle user.

2, check the use of crontab

Use the Super User (root) to view the cron.deny file with the vi command under / usr / var / .. If the owner Oracle of the database is listed, you can delete it.

3. Create Oracle's crontab file

Use the Oracle user to start establishing the CRONTAB file of the Oracle user by using the command crontab -e oracle. The content is:

00 17 * * 1-5 "/usr/oracle/backup.sh"

After the deployment, you will find a newly added Oracle file in / var / spool / cron / crontabs, and its role is running "/usr/oracle/backup.sh" on Monday to Friday every day. .

Here, the system will be sent to the Oracle user in the form of each backup through Mail. When operating the above, it is recommended to back up the crontab files of other users (especially root) in / var / spool / cron / crontabs to avoid influence on the system.

转载请注明原文地址:https://www.9cbs.com/read-87470.html

New Post(0)