In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
The main content of this article is about "script sharing for centos to automatically back up mysql database every day". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the script sharing of centos automatically backing up mysql database every day.
The script is as follows
#! / bin/bash
# feature description: this feature is used for backup
# date of writing: 2010-12-06
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
Export PATH
# Database user name
Dbuser='root'
# Database password
Dbpasswd='123456'
# Database name, which can define multiple databases separated by spaces, such as test test1 test2
Dbname='test1 test2'
# backup time
Backtime= `date +% Y% m% d% H% M% S`
# Log backup path
Logpath='/second/backup'
# data backup path
Datapath='/second/backup'
# logging header
Echo'"backup time is ${backtime}, backup database table ${dbname} start" > > ${logpath} / log.log
# formal backup of the database
For table in $dbname; do
Source= `mysqldump-u ${dbuser}-p$ {dbpasswd} ${table} > ${logpath} / ${backtime} .sql`2 > > ${logpath} / mysqllog.log
# backup succeeded in the following
If ["$?" = = 0]; then
Cd $datapath
# compress the database to save hard disk space
Tar jcf ${table} ${backtime} .tar.bz2 ${backtime} .sql > / dev/null
# Delete the original file, leaving only the compressed file
Rm-f ${datapath} / ${backtime} .sql
Echo "Database table ${dbname} backup succeeded!" > ${logpath} / mysqllog.log
Else
# if the backup fails, do the following
Echo "backup of database table ${dbname} failed!" > > ${logpath} / mysqllog.log
Fi
Done
Execute the script regularly:
Method:
1 、
Execute crontab-e
Enter the following:
_
00 00 * / bin/bash yourpath/mysqlbak.sh
2 、
Open the automatic execution file
Vi / etc/crontab
Add the following to etc to automate the task.
00 00 * root / mysqlbak.sh
The above two 00 00 * automatically execute scripts in the early hours of each day.
Time-sharing, day, month and week order
M: minutes (0-59). Every minute is represented by * or * / 1.
H: hours (0-23). (0 represents 0 o'clock)
D: days (1-31).
M: month (1-12).
D: the day of the week (0600 is Sunday).
3 、
Redhat method:
Redhat's crontab calls 4 directories by time (/ etc/cron.hourly: per hour; / etc/cron.daily: per
Days; / etc/cron.weekly: weekly; / etc/cron.monthly: monthly) the way scripts come out and run.
In Redhat, you just need to copy the script you just edited to the appropriate directory.
Cp / autobackupmysql.sh etc/cron.daily
Restart etc
/ etc/rc.d/init.d/crond restart
At this point, I believe you have a deeper understanding of "centos script sharing for automatically backing up mysql database every day". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.