How to use Linux to Complete Oracle automatic physical backup

Source: Internet
Author: User
Tags compress archive

Source: Network/Editor: getting started with programming Author: E Jian

The goal of this article is to execute a shell script to complete the entire process of automatic Oracle database backup, and to generate compressed files in the current directory. The specific implementation steps are as follows:

1. log on to Linux as an oracle user.

2. Create a database. srcept file to generate some parameter information of the backup database and save it in the file database. parm.

This information has an important reference for restoring the database in the future. Therefore, you need to save this information during the physical backup process. You can also write other important information in this script.

$ VI database. srcept

Spool database. parm

-- This is the list of system parameters of the current backup database.

Select * from V $ parameter;

-- This is part of the character set parameter of the current backup database

Select * from props $;

-- This is the file storage location and name of the current backup database.

Select * from V $ datafile;

-- This is the current backup database control file storage location and name

Select * from V $ controlfile;

-- This is the location and name of the log file stored in the current backup database

Select * from V $ logfile;

-- You can add other important information here.

-- Start generating the backup shell file. For details, refer to backup. Sh.

Spool off

Spool backup. Sh

Select 'cp' | Name | 'backup/'from V $ datafile;

Select 'cp' | Name | 'backup/'from V $ controlfile;

Select 'cp' | member | 'backup/'from V $ logfile;

Spool off

Shutdown immediate

Exit

!

3. Modify the backup. Sh file generated in the previous step and execute it to complete the operating system backup of the database file. For clarity, name this script file alterbackup. Sh.

$ VI alterbackup. Sh

Echo "this script completes the process of copying database data files, control files, and log files to the current directory"

Cat backup. Sh | grep 'cp/'> C. Sh

# This statement extracts all statements starting with "CP/" in backup. Sh to generate a new file C. Sh.

Rm backup. Sh

Mv c. Sh backup. Sh

Chmod + x backup. Sh

. Backup. Sh

# Note: there is a space between the dot "." And backup. Sh.

4. Create a database STARTUP script to start the database after the backup is completed. Name the script startup. script.

$ VI startup. Script

Spool startstatus. readme

-- Start the database

Startup

-- After the database is started, you can check the startstatus. readme file to check the database startup status.

Spool off

Exit

!

5. To save disk space and copy data to other storage locations, create a shell file gzip. script to compress the backup data files. Note that the time is specified in the file name when the backup file is generated.

$ VI gzip. Sh

Echo "Start the Backup File compression process"

Thedate = 'date + % Y. % m. % d. % H. % m'

# Note: There is a backticks before and after the string, not single quotes.

OUTFILE = $ thedate

Tar-CVF backup1_outfile.tar backup /*

# Generate a file for all the files backed up to the backup directory

Gzip backupappsoutfile.tar

# Compress archive files to save hard disk space

Rm-r backup # Delete uncompressed files

6. Organize the content generated from step 1 to step 2 into a shell file begin. Sh. Before that, run the following command:

$ Chmod + x alterbackup. Sh

$ Chmod + x gzip. Sh

$ VI begin. Sh

Echo starts the automatic physical processing of the data library. The shellwill generate the backup.gz file under the current directory,

This file contains some database parameter information and database physical files ......"

Mkdir backup

Sqlplus internal/Oracle <database. srcept

. Alterbackup. Sh

Sqlplus internal/Oracle <startup. Script

. Gzip. Sh

Echo processing: the data warehouse is automatically in the physical processing process. Check backup.tar.gz in the current directory"

7. Added backup statements for database parameter files.

Database parameter files are usually stored in the "Oracle/admin/database name/pfile/" directory. The file naming rules are "init + database name. the default database name is orcl, which can be modified according to the database installation name. If you do not know where the file is stored, run the following command to find it:

$ Find $ ORACLE_HOME-name 'initorcl. ora'

This statement may display/u01/APP/Oracle/product/8.1.7/dbs/initorcl. ora, because there is a link file in Linux, you need to check whether the displayed file is a link file. If yes, you need to further check its original file.

$ Ll/u01/APP/Oracle/product/8.1.7/dbs/initorcl. ora

In this example, the file is a link file pointing to/u01/APP/Oracle/admin/orcl/pfile/initorcl. ora. To this end, you can modify alterbackup. Sh in step 1. The Modification result is as follows (in bold, this statement needs to be modified according to the database installation situation ):

......

Chmod + x backup. Sh

CP/u01/APP/Oracle/admin/orcl/pfile/initorcl. ora backup/initorcl. ora

. Backup. Sh

# Note: there is a space between the dot "." And backup. Sh.

8. when preparing for backup, run the "ls-L (or LL)" command to check the current directory. At this time, there should be several files: alterbackup. sh, begin. sh, database. script, Gzip. sh, startup. script.

After that, execute the following command:

$ Chmod + x begin. Sh

If everything is done, you can execute begin. Sh to complete the backup process:

. Begin. Sh

# Note that there is a space before begin. SH and the first vertex. ---Www.bianceng.cn

You only need to run begin. Sh each time you need a backup. Here, you can also use crontab to automatically back up data as planned. For details about how to use crontab, refer to relevant information or query it online. This article will not introduce it any more.

Using this method for physical backup not only backs up the data files of the database, but also records some important information of the database (step 1: database. parm
File), which is very important for future data recovery. Note that the method provided in this article requires sufficient disk space (although only the compressed file of the backup file is retained
To the readers.

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.