Complete Oracle Automatic Physical Backup with Linux

xiaoxiao2021-03-06  58

Linux Oracle automatically with the completion of physical backup: Wang Quanhai dispatch time: 2003.09.09 10:53:24 Oracle Database provides several data backup methods, but the most used or the use of logical backup exp, and physical backup (including online backup And offline backups is not much used. Its main reason is that the physical backup process is more complicated and it is not easy to master. This article describes the operational steps of the physical backup with an Oracle database in Linux, which is described as an example. It is description of the operational steps of the physical backup. It is desirable to help more Oracle database administrators understand this physical backup process to avoid unnecessary data loss. The goal of this article is to complete the entire process of automatic backup of the Oracle database by performing a shell script, and can generate its compressed files in the current directory. The specific implementation steps are as follows: 1. Log in to the Linux system as an Oracle user. 2. Establish a Database.Srcipt file to generate some of the parameter information of the backup database and save it in the file Database.parm. This information has important reference functions for future recovery databases, so in the process of physical backup, you need to save this information, you can also write other important information in this script.

$ VI DATABASE.SRCIPT

Spool data.parm

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

Select * from V $ Parameter;

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

SELECT * from ProPs $;

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

SELECT * from V $ datafile;

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

SELECT * FROM V $ controlfile;

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

SELECT * from V $ logfile;

- You can add some other important information here.

- Start generating backup shell files, 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. To clearly, name this script as file alterbackup.sh.

$ vi alterbackup.sh

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

Cat backup.sh | grep 'cp /'>c.sh

# This statement extracts all the statements starting with "CP /" in the "CP /" to generate new files C.SH

RM backup.sh

MV C.SH backup.sh

CHMOD X backup.sh

. backup.sh

# 注意 点 "" There is a space between the point number "."

4. Establish a database launch script to start the database after completing the backup, name the script Startup.Script.

$ VI Startup.script

Spool StartStatus.Readme

- Start launching the database

Startup

- Database starts complete, you can view the StartStatus.Readme file to check the database startup

Spool offexit

!

5. To save disk space and copy to other storage locations, build the shell file gzip.script to complete the compression of the backup data file. Note When you generate a backup file, you indicate the time in the file name.

$ vi gzip.sh

Echo "Start the compression process of backup files"

TheDate = 'DATE % Y.% m.% d.% h.% M'

# Note: There is an anti-quoter before and after the string, not single quotes

Outfile = $ thisdate

TAR-CVF Backup $ OUTFILE.TAR Backup / *

# Generate a file with all the files backup to the backup directory

Gzip Backup $ OUTFILE.TAR

# Compress file files to save hard disk space

Rm -r backup # Delete those files without compression

6. Organize the above steps 2 to 5 to a shell file begin.sh, but you need to run the following command before this:

$ chmod x alterbackup.sh

$ chmod x gzip.sh

$ vi begin.sh

"Echo" starts the automatic physical backup process of the database, which will generate the backup.gz file in the current directory.

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

MKDIR Backup

SQLPlus Internal / Oracle

ALTERBACKUP.SH

SQLPlus Internal / Oracle

Gzip.sh

Echo "Database Automatically ends the physical backup process, please check backup.tar.gz in the current directory"

7. Add the backup statement of the database parameter file. The database parameter file is usually stored in the "Oracle / Admin / Database Name / PFile /" directory, its file naming rules are "Init Database Name. ORA", the database name default name orcl, can be modified according to the database installation name. If you don't know where the file is stored, you can use the following command to find:

$ 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, so to view the displayed file is not a link file, if yes, Further review its original file.

$ ll /u01/app/oracle/product/8.1.7/dbs/initorcl.ora

This example shows that the file is a link file, which points to /u01/app/oracle/admin/orcl/pfile/initorcl.ora. To this end, the alterbackup.sh of step 3 can be modified, and the modifications are as follows (bold display, the statement needs to be modified according to the database installation):

......

CHMOD X backup.sh

Cp /u01/app/oracle/admin/orcl/pfile/initorcl.ora backup / initorcl.ora

. backup.sh

# 注意 点 "" There is a space between the point number "."

8. When you are ready for backup, use the LS -L (or LL) command to check the current directory, there should be such files at this time: alterbackup.sh, begin.sh, database.script, gzip.sh, startup. Script. Thereafter, the command should be performed: $ chmod x begin.sh

If everything is done, you can execute Begin.sh to complete the backup process:

Begin.sh

# Note Begin.sh has a space before the previous order.

Each time you need to make a backup, you only need to run begin.sh. You can also use crontab to automatically complete the scheduled backup, for how to use crontab, please refer to the relevant information, you can also query online. This article is no longer introduced. With this method, the physical backup process is used, not only the database's data file is backed up, but also record some important information for the database (in the Database.parm file in step 2), which is very important for future recovery data. Finally, the reader is to note that the method provided herein requires a large enough disk space (although only the compressed files of the backup file), this lack leaves the reader to make up. Note: This article is used under the Redhat 7.3, Oracle 8i Enterprise Edition Release 8.1.7 for Linux Using / BIN / BASH to debug pass.

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

New Post(0)