Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Oracle to set up scheduled tasks to back up database in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to use Oracle to set up scheduled tasks to back up the database in Linux? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

1. View the character set of the database

The character set of the database must be consistent with the environment variables set under Linux, otherwise there will be garbled codes.

The following two sql statements can be found:

Select * from nls_database_parameters t where t.parameterized requests NLSparts CHARACTERSETATIONAL select * from v$nls_parameters where parameter='NLS_CHARACTERSET'

The query result is: NLS_CHARACTERSET AL32UTF8

2. Log in to the oracle server with the oracle user and create the relevant directory

Create a directory mkdir-p / home/oracle/dbbak/data for backup data

Create the backup script directory mkdir-p / home/oracle/dbbak/shell

Create the export data log directory mkdir / home/oracle/dbbak/log

3. Create a script file under the script directory

Vi / home/oracle/dbbak/shell/dbbak.sh

The contents of the script:

# [plain] view copyright copywriting NLS_LANG=AMERICAN_AMERICA.AL32UTF8mkdir binAccorp shexport ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1export ORACLE_SID=orclexport PATH=$PATH:$HOME/bin:$ORACLE_HOME/binexport DATA_DIR=/home/oracle/dbbak/dataexport LOGS_DIR=/home/oracle/dbbak/logexport DELTIME= `date-d "30 date" +% Y% m% d`export BAKUPTIME= `date +% Y% m% d% H% M% S`export NLS_LANG=AMERICAN_AMERICA.AL32UTF8mkdir-p $DATA_DIRmkdir-p $LOGS_DIRecho "Starting bakup..." echo "Bakup filepath$DATA_DIR/$BAKUPTIME.dmp" exp user/pwd@orcl file=$DATA_DIR/orcl$BAKUPTIME.dmp log=$LOGS_DIR/orcl$BAKUPTIME.logecho "Delete the file bakup before 30days...filepath: $DATA_DIR/orcl$DELTIME*.dmp" rm-rf $DATA_DIR/orcl$DELTIME*.dmprm-rf $LOGS_DIR/orcl$DELTIME*.logecho "Delete the file bakup successfully." echo "Bakup completed."

Modify the relevant content according to your own needs:

Export DELTIME= `date-d "30 days ago" +% Y% m% d` configure the time to retain the data. Here, you can retain the data for 30 days and modify it according to your own needs and the storage space of the server. Export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 character encoding format, which needs to be consistent with the result of the query in step 1; exp DISPLAY/DISPLAY@orcl file=$DATA_DIR/orcl$BAKUPTIME.dmp log=$LOGS_DIR/orcl$BAKUPTIME.log

Export statement, full table export, can be modified as needed, exp user name / password @ SID file=dmp file full path log= log file full path

4. Modify the execution permission of the script file

Chmod 777 dbbak.sh

Test whether it can be executed:. / dbbak.sh

Export terminated successfully without warnings. Indicates that there is no problem with the export. If there is a problem, solve it.

5. Add scheduled tasks

Under Oracle users

Crontab-e

Insert: 59 23 * / home/oracle/dbbak/shell/dbbak.sh

Indicates that the script is executed at 23:59 every day

Restart crond:

Service crond restart

6. Import dmp file

Delete all tables under the corresponding users before import to avoid problems with table data after import:

Sqlplus user/pwd / / user name password login database SQL > SELECT 'drop table' | | table_name | |'; 'FROM USER_TABLES ORDER BY TABLE_NAME

Then execute the results of the query

Execute this line to avoid garbled comments on the table field:

Export NLS_LANG=AMERICAN_AMERICA.AL32UTF8; import data: imp DISPLAY/DISPLAY file=/home/oracle/dbbak/data/orcl20191121113703.dmp fromuser=DISPLAY touser=DISPLAY ignore=y;// ignore=y ignores errors and continues to read the above. Have you learned how to use Oracle to set up a scheduled task to back up the database in Linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report