In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article is mainly about the use of shell scripts to achieve regular backup of Oracle database, and delete backup files before a specified number of days. Daniel who has mastered shell, please pass by decisively. If there are any similarities in this article, it is purely intentional.
First introduce the test environment, and then explain the specific steps. The first article of this blog will try to do better in the future. Please forgive me if it is not well written. You are welcome to put forward all kinds of suggestions, such as the content selection of the article, the level of detail of the operation steps, and so on.
Environment:
Operating system: CentOS
IP address: 192.168.1.2
Port: 1521
SID:orcl
Oracle version: Oracle11g
Specific steps:
(1) root logs in to Oracle database server
# create a new backup directory
Mkdir / home/bak/orcl_data
# set directory permissions, which are set by users and groups when Oracle is installed
Chown-R oracle:oracle / home/bak/orcl_data
(2) create a backup script
# create a new file and enter the code to save it. The location of the script is saved according to personal habits.
Vim / usr/local/scripts/oracle_bak.sh
#! / bin/sh
# add the system environment variable for Oracle to run user oracle to facilitate the execution of Crontab scheduled tasks
# oracle user's system environment variable path is / home/oracle/.bash_profile
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:/lib:/usr/lib
Export LANG=C
Export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
# get date and time
Date= `date +% Yee% masked% d`
# set to delete backups 15 days ago
Days=15
# Oracle server IP, port, SID
Orsid= `192.168.1.2: 1521 / orcl`
# back up this user's data
Orowner=osgnu
# users who perform backups must have backup permissions
Bak_user=osgnu
# password of the user who performed the backup
Bak_pass=osgnu
# the path of backup, which is created in advance
Bak_dir=/home/bak/orcl_data
# backup database name
Bak_data=$orowner "_" $date.dmp
# name of the log file generated by backup
Bak_log=$orowner "_" $date.log
# saved Oracle database backup file
Ordatatar=$orowner "_" $date.tar.gz
# enter the backup directory
Cd $bak_dir
# create directories according to the Oracle users who need to back up
Mkdir-p $orowner
# enter the directory
Cd $orowner
# perform backup
Exp $bak_user/$bak_pass@$orsid grants=y owner=$orowner file=$bak_dir/$orowner/$bak_data log=$bak_dir/$orowner/$bak_log
# Compression
Tar-zcvf $ordatatar $bak_data $bak_log
# Delete backup files
Find $bak_dir/$orowner-type f-name "* .dmp"-exec rm {}\
# Delete log files
Find $bak_dir/$orowner-type f-name "* .log"-exec rm {}\
# Delete backups from 15 days ago
Find $bak_dir/$orowner-type f-name "* .tar.gz"-mtime + $days-exec rm {}\
# Save exit
: wq!
# add execution permission
Chmod + x / usr/local/scripts/oracle_bak.sh
(3) Editing scheduled tasks
Crontab-e or vim / etc/crontab then add the following
# execute backup script as oracle user at 01:30 every morning
30 1 * oracle / usr/local/scripts/oracle_bak.sh
# Save exit
: wq!
# restart crond
Service crond restart
Backup completed before automatically backing up oracle and deleting the specified number of days.
Www.osgnu.com warm reminder: the original content of BruceZ is copyrighted. Please indicate the source and the original link when reproduced.
Link to this article: www.osgnu.com/shell/1.html
For reprint, please indicate the source: OSGNU > > Linux automatically back up Oracle and delete the backup before the specified number of days
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.