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 set up automatic database backup every day in Linux

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

Share

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

This article is about how to set up a daily automatic backup database in Linux. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.

one。 First find the environment variable of the database

If you are under a root account, you must first log in to the account where the database is located.

Su oraclecat / .bash_profile

Export PATHexport ORACLE_BASE=/home/nnc_db/appexport ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1export PATH=$PATH:$ORACLE_HOME/binexport ORACLE_SID=orcl

The environment variable has been found!

two。 Edit the backed up script file

Vi bak.sh

Copy and paste the environment variables into the bak.sh file first

Then define a variable date (its function is to name the files that are backed up every day for easy identification), and use the expdp command to export the database as follows:

Date=$ (date +% Y%m%d) expdp database account / database password @ database instance name dumpfile=$ {date} _ db_auto_backup.dmp schemas= database account name compression=all

Exit save.

three。 Set up scheduled tasks using the crontab command of Linux

Crontab-e

The role of crontab-e is to set up scheduled tasks using a text editor (the specific usage of crontab will not be discussed here)

Enter it in a text editor after input

0 0 * / home/nnc_db/bak.sh

The above code means that the bak.sh file under / home/nnc_db executed at 00:00 every day, that is, the file created in step 2, needs to be adjusted according to its own backup time and file directory.

Then restart the crond service

Service crond restart

four。 Test whether the task runs successfully

According to the information I collected on the Internet, a friend said that the crontab-e setting will not take effect three minutes after the setting is successful! That is to say, if you set up a task at 10:00 in the morning and want to test whether it can be successful, set the next scheduled task to 10:02, there may be a problem! But here I use

* / home/nnc_db/bak.sh

Set to run every minute, and there is no problem.

There is also a novice pit is that you directly run the script file will output a detailed process on the command line, while setting a scheduled task to run is unresponsive! So if you want to see whether your script runs automatically, you need to look at the log file under / var/spool/mail/, as shown in the figure.

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

The above is how to set up automatic backup of the database every day in Linux. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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