In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the script for automatic backup of mysql under linux. In daily operation, I believe that many people have doubts about the script for automatic backup of mysql under linux. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "script for automatic backup of mysql under linux". Next, please follow the editor to study!
The script is placed on / home/user/_backup.sh
Crontab
# crontab-l
# m h dom mon dow command
28 16 * / home/user/mysql_backup.sh
The script is as follows
#! / bin/sh # mysql_backup.sh: backup mysql databases and keep newest 5 days backup. # # Last updated: 20 March 2006 #-# This is a free shell script under GNU GPL version 2.0 or above # Copyright (C) 2006 Sam Tang # Feedback/comment/suggestions : http://www.real-blog.com/ #-# your mysql login information # db_user is mysql username # db_passwd is mysql password # db_host is mysql Host #-db_user= "root" db_passwd= "password" db_host= "localhost" # the directory for story your backup file. Backup_dir= "/ home/mybackup" # date format for backup file (dd-mm-yyyy) time= "$(date +"% d-%m-%Y ")" # mysql Mysqldump and some other bins path MYSQL= "/ usr/local/mysql/bin/mysql" MYSQLDUMP= "/ usr/local/mysql/bin/mysqldump" MKDIR= "/ bin/mkdir" RM= "/ bin/rm" MV= "/ bin/mv" GZIP= "/ bin/gzip" # check the directory for store backup is writeable test!-w $backup_dir & & echo "Error: $backup_dir is un-writeable." & exit 0 # the directory for story the newest Backup test!-d "$backup_dir/backup.0/" & & $MKDIR "$backup_dir/backup.0/" # get all databases all_db= "$($MYSQL-u $db_user-h $db_host-p$db_passwd-Bse show databases)" for db in $all_db do $MYSQLDUMP-u $db_user-h $db_host-p$db_passwd $db | $GZIP-9 > "$backup_dir/backup.0/$time.$db.gz" done # delete the Oldest backup test-d "$backup_dir/backup.5/" & & $RM-rf "$backup_dir/backup.5" # rotate backup directory for int in 43 2 10 do if (test-d "$backup_dir" / backup. "$int") then next_int= `expr $int + 1` $MV "$backup_dir" / backup. "$int"$backup_dir" / backup. "$next_int" fi done exit 0
Note:
Mysql runs as mysql and fails if it is not writable to / home / mybackup
Chmod 777 / home/mybackup problem solved
At this point, the study of "script for automatic backup of mysql under linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.