Automatic Oracle Database Backup (1)

Source: Internet
Author: User

 

I believe that many system administrators are doing the same job every day-backing up data. Once the system fails and data recovery is required, the system is powerless. It would be nice to set a fixed time every day for the system to automatically back up data! Next, I will talk about the automatic backup of Oracle databases in a UNIX environment based on my practical experience.

We plan to allow the database to perform export backup at a.m., copy the backup file to the tape at a.m., and copy the backup file to another UNIX machine at a.m, to do this, we can perform the following operations:

1. Export the database

The export command backs up data in the database into a binary file. There are usually three modes: user mode, table mode, and whole database mode. This document uses the user mode. before backup, you must create a backup directory to hold backup files. For example, you can create a/backup directory. Then we can create two files, ora-backup and tar-backup, respectively, in the UNIX Oracle directory or in other directories. It should be noted that the Oracle parameter needs to be initialized in the previous file. For convenience, we may wish to put the initialization command in a file named ora-env ), then the first file calls it.

1. The ora-env file initializes Oracle parameters. The content is as follows:

ORACLE-HOME = $ ORACLE-HOME; export ORACLE-HOME

ORACLE-SID = ora73; export ORACLE-SID

ORACLE-TERM = sun; export ORACLE-TERM

LD-LIBRARY-PATH = $ ORACLE-HOME/lib; export LD-LIBRARY-PATH

ORA-NLS32 = $ ORACLE-HOME/ocommon/nls/admin/data; export ORA-NLS

PATH =.:/usr/ccs/bin:/usr/ucb: $ ORACLE-HOME/bin: $ PATH; export PATH

DISPLAY = host1: 0; export DISPLAY

NLS-LANG = american-america.zhs16cgb231280; export NLS-LANG

2. the ora-backup file exports the Database export, and the exported file name can be set at will. This document specifies the letter "xx" and the date of the day, that is, if the date of the day is January 1, December 10, the exported file name is "xx1210.dmp", which is different from the backup file of other dates.

Ora-backup file content:

./Oracle/ora-env

# Initializing an Oracle database

Rq = 'date + "% m % d ″′

# Assign the date of the day to the variable rq

Rm/backup /??

# Clearing/backup directories

Exp test/test file =/backup/xx $ rq. dmp log =/backup/xx $ rq. log

This command is used to export the data of user test at the $ prompt. The exported files and logs are stored in the/backup directory.

Ii. tape backup

The tar-backup file copies the data files exported using the export command to the tape.

Tar-backup file content:

Tar rvf/dev/rmt/0n/backup /??

This command backs up files generated on the current day in the/backup Directory to the tape. In this file, the tar command uses three parameters. The r option indicates that the file is transferred to the tape without being damaged.

The original content of the tape. The v option indicates that the file information is displayed during the copy process. The f option is followed by the name of the tape device to specify where the file is copied. The n option indicates that the tape drive is not replayed. /Dev/rmt

/0 indicates the first tape drive of the UNIX host. Similarly,/dev/rmt/1 indicates the second tape drive of the UNIX host, and so on.

After writing the ora-env, ora-backup, and tar-backup files, run the following commands:

Chmod 755 ora-env

Chmod 755 ora-backup

Chmod 755 tar-backup

In this way, all three files become executable files.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.