I believe that many system administrators are doing the same job almost every day, that is, backing up relevant data. In case of negligence one day, and the system suffers some faults on this day, and data recovery is required, there will be nothing to do at this time. Let's talk about the automatic backup of Oracle databases in UNIX environments, which can be used as an example.
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:
Export Database
The export command backs up data in the database into a binary file. There are usually three modes: user mode, table mode, and the entire Oracle 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 Oracle directory of UNIX (or another directory. 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 (the file name should be set to 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 Oracle 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
Initialize an Oracle database
- rq=′date +″%m%d″ ′
Assign the date of the current day to the variable rq
- rm /backup/
Clear/backup Directory
- exp test/test file=/backup/xx$rq.dmp log=/backup/xx$rq.log
This command is used to export the data of the user test (whose password is also test) at the $ prompt. The exported files and logs are stored in the/backup directory.
Article by: http://database.ctocio.com.cn/448/8997448.shtml