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 realize mysql remote automatic backup under Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly explains how to achieve mysql remote automatic backup under Linux, the content is clear, interested friends can learn, I believe it will be helpful after reading it.

Foreword:

Basically, mysql backup is an essential part of whether it is for our own use or for deploying servers to customers. Here is how I achieve remote automatic backup on linux.

Mysql_backup.sh is used to back up data mysql_restore.sh is used to restore data remove_backup.sh is used to delete backup files from some time ago

I. data backup preparation

1.1 create a backup directory

Note: here I am. Put the backup file under / data/backup/mysql and the script under / data/backup.

Some create a folder (ignore if created)

Mkdir-p / data/backup/mysqlcd / data/backup

1.2 create a script file

Create a mysql_backup.sh script

Vi mysql_backup.sh

Paste the following script content

#! / bin/bash# if necessary Change it here by yourself # db_user='root'#db_password= `cat / data/www/mysql_ password`db _ name='wuqilong'backup_dir='/data/backup/mysql/'current_time=$ (date +'% Ymuri% mmi% dice% H% M% S') filepath=$backup_dir$current_time'.sql.gz'# does not use $db_password $db_user here Has been written to the configuration file echo 'start exporting database...' mysqldump-- defaults-extra-file=/data/backup/my_mysql.cnf $db_name | gzip > $filepathecho 'exported successfully The file name is:'$filepath

Create a new configuration file, which is in our current directory, namely / data/backup

Vi my_mysql.cnf

Here are the contents of the file. Here you can set the upper limit of the file size allowed to be exported.

Fill in the host here that you need to backup from that server.

[mysqldump] max_allowed_packet = 400Mhost=ip address (192.168.1.address *) user=rootpassword='root' [mysql] host=ip address (192.168.1.address *) user=rootpassword='root'

In this way, the export shell script has been written, and then add permissions to it.

Chmod + x. / mysql_backup.sh

You can now use the following command to export

Sh. / mysql_backup.sh# check the result ll. / mysql

After reading the above content, do you have a further understanding of how to achieve mysql remote automatic backup under Linux? if you want to learn more, you are 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.

Share To

Wechat

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

12
Report