In Linux, the Oracle database is automatically backed up and the backup days ago is deleted.

Source: Internet
Author: User

Note:
Oracle Database Server
Operating System: CentOS
IP: 192.168.0.198
Port 1521
SID: orcl
Oracle Database Version: Oracle11gR2

Specific operations:

1. log on to the server as the root user.
Mkdir-p/backup/oracledata # create an Oracle Database backup Directory
Chown-R oracle: oinstall/backup/oracledata-R # Set the directory permission to oracle users in the oinstall user group (oracle users and user group oinstall are set when Oracle database is installed)

2. Create an Oracle database backup script
Vi/backup/oracledata/ordatabak. sh # create a file and enter the following code
#! /Bin/sh
Export ORACLE_BASE =/data/oracle
Export ORACLE_HOME = $ ORACLE_BASE/product/11.2.0/db_1
Export ORACLE_SID = orcl
Export ORACLE_TERM = xterm
Export PATH = $ ORACLE_HOME/bin:/usr/sbin: $ PATH
Export LD_LIBRARY_PATH = $ ORACLE_HOME/lib:/usr/lib
Export
Export NLS_LANG = AMERICAN_AMERICA.ZHS16GBK
# The above code is set for the system environment variables of the Oracle database running account oracle, which must be added; otherwise, the crontab task plan cannot be executed.
# Path of the oracle system environment variable:/home/oracle/. bash_profile
Date = 'date + % Y _ % m _ % d' # obtain the current date and time of the system
Days = 7 # Delete the backup file 7 days ago
Orsid = '192. 168.0.198: 192/orcl '# Oracle Database Server IP address, port, SID
Orowner = JUSTIN # Back up data under this user
Bakuser = JUSTIN # This user must have the backup operation permission to perform the backup.
Bakpass = JUSTIN # user password for executing remarks
Bakdir =/backup/oracledata # backup file path, which must be created in advance
Bakdata = $ orowner "_" $ date. dmp # backup database name
Baklog = $ orowner "_" $ date. log # Name of the log file generated during Backup execution
Ordatabak = $ orowner "_" snapshot # last saved Oracle Database Backup File
Cd $ bakdir # enter the Backup Directory
Mkdir-p $ orowner # create a directory for Oracle users who back up data as needed
Cd $ orowner # enter the Directory
Exp $ bakuser/$ bakpass @ $ orsid grants = y owner = $ orowner file = $ bakdir/$ orowner/$ bakdata log = $ bakdir/$ orowner/$ baklog # execute backup
Tar-zcvf $ ordatabak $ bakdata $ baklog # compress Backup files and log files
Find $ bakdir/$ orowner-type f-name "*. log"-exec rm {}\; # Delete the backup file
Find $ bakdir/$ orowner-type f-name "*. dmp"-exec rm {}\; # delete a log file
Find $ bakdir/$ orowner-type f-name "* .tar.gz"-mtime + $ days-exec rm-rf {}\; # Delete backups 7 days ago (note: {} \ There is a space in the middle)
: Wq # Save and exit
Chmod + x/backup/oracledata/ordatabak. sh # Add the script execution permission

3. vi/etc/crontab # edit the system task plan and add the following code to the last line.
30 2 * oracle/backup/oracledata/ordatabak. sh # at 02:30 every day, oracle users execute ordatabak. sh to back up files
: Wq! # Save and exit
Service crond restart # restart crond
Every morning at 02:30, the database is automatically backed up to the/backup/oracledata/justindirectory, saved as a. tar.gz compressed file, and deleted seven days ago, that is, only the data of the last seven days is retained.
Note: All the above Code is entered in the English half-width state.

Now, the Oracle database is automatically backed up in Linux and the backup tutorial is completed a specified number of days ago.

Recommended reading:

Oracle uses the old control file to back up and restore the new data file

Basic Oracle tutorial-copying a database through RMAN

Reference for RMAN backup policy formulation

RMAN backup learning notes

Oracle Database Backup encryption RMAN Encryption

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.