In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-10-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how the CentOS/RHEL system automatically backs up the MySQL database every day. It is very detailed and has a certain reference value. Interested friends must finish reading it!
1. First, create the following three folders under the server: / bak, / bak/bakmysql, / bak/bakmysqlold.
[root@server21] # mkdir-p / bak/bakmysql {, old}
Create a shell script under the / bak/bakmysql folder:
[root@server21 ~] # touch / bak/bakmysql/backup.sh
To authorize a file:
[root@server21 ~] # chmod 755 / bak/bakmysql/backup.sh
two。 Edit the shell script:
[root@server21 ~] # vim / bak/bakmysql/backup.sh
#! / bin/bash
Cd / bak/bakmysql
Echo "You are in bakmysql directory"
Mv bakmysql* / bak/bakmysqlold
Echo "Old databases are moved to bakmysqlold folder"
Now=$ (date + "% Y-%m-%d")
File=bakmysql-$Now.sql
Mysqldump-uroot-paired password 'db_bbs > $File
Echo "Your database backup successfully completed"
SevenDays=$ (date-d-7day + "% Y-%m-%d")
If [- f / bak/bakmysqlold/bakmysql-$SevenDays.sql]; then
Rm-rf / bak/bakmysqlold/bakmysql-$SevenDays.sql
Echo "You have delete 7days ago backup file"
Else
Echo "7 days ago backup file not exist"
Fi
Change the red font in the 3.Shell script mysqldump-uroot-paired password 'db_bbs > $File statement to your own mysql database user, password, and database name, respectively. The script first moves the backup files whose bakmysql starts with the file name in the / bak/bakmysql folder to / bak/bakmysqlold, then generates the latest backup files, and finally determines whether the files from seven days ago exist in the / bak/bakmysqlold folder, deletes them, and ends at last. This automatically backs up the database scripts for the last seven days.
4. Set the shell script to be executed automatically every day:
[root@server21 ~] # vim / etc/crontab add this line at the end (please refer to the notes in / etc/crontab for details)
0 0 * root / bak/bakmysql/backup.sh
Restart crontab:
[root@server21 ~] # / sbin/service crond restart
If crontab is not set to boot, you can set it to boot as follows:
[root@server21 ~] # chkconfig-level 35 crond on
The above is all the contents of the article "how to automatically back up MySQL database in CentOS/RHEL system every day". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.