Get the App
SLTechnology News&Howtos  ›  Database  › 

How to realize mysql remote automatic backup under Linux

Shulou Source: shulou.com Published: 2022-06-01 11:24:16 10月16日 Update

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.

Tags: Backup file content script data remote face address server directory learning service configuration success next upper limit interest preface command size Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology vpn Microsoft Apple