How to automatically backup mysql remotely under Linux

How to automatically backup mysql remotely under Linux

Preface:

Basically, whether it is for our own use or deploying servers for customers, MySQL backup is an indispensable part. Here I will share with you how I achieve automatic off-site 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 a period of time ago

1. Data backup preparation

1.1 Create a backup directory

Note: Here I put the backup file under /data/backup/mysql and the script under /data/backup

Create a folder (if it has been created, please ignore it)

mkdir -p /data/backup/mysql
cd /data/backup

1.2 Create a script file

Create mysql_backup.sh Script

vi mysql_backup.sh

Paste the following script content

#!/bin/bash
# If necessary, change this yourself #db_user='root'
#db_password=`cat /data/www/mysql_password`
db_name='wuqilong'
backup_dir='/data/backup/mysql/'
current_time=$(date +'%Y-%m-%d_%H%M%S')
filepath=$backup_dir$current_time'.sql.gz'
#$db_password $db_user is not used here, it has been written into the configuration file echo 'Start exporting the database...'
mysqldump --defaults-extra-file=/data/backup/my_mysql.cnf $db_name | gzip > $filepath
echo 'Export successful, file name: '$filepath

Create a new configuration file in our current directory, i.e. /data/backup

vi my_mysql.cnf

The following is the file content. Here you can set the upper limit of the file size allowed to be exported

The host here is the server you need to back up from.

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

The exported shell script is now ready. Next, add permissions to it.

chmod +x ./mysql_backup.sh

Now you can use the following command to export

sh ./mysql_backup.sh
# Check the results ll ./mysql 

Summarize

This is the end of this article about MySQL automatic remote backup under Linux. For more information about MySQL automatic remote backup under Linux, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MySQL multi-instance deployment and installation guide under Linux
  • MySQL 8.0.25 installation and configuration tutorial under Linux
  • How to start multiple MySQL databases on a Linux host
  • Steps and pitfalls of upgrading linux mysql5.5 to mysql5.7
  • Solve the problem of no my.cnf file in /etc when installing mysql on Linux
  • Steps to install MySQL using Docker under Linux
  • Detailed explanation of how to manually deploy a remote MySQL database in Linux
  • Detailed explanation of the idea of ​​using mysqldump+expect+crontab to implement mysql periodic cold backup in linux
  • Aliyun Linux compile and install php7.3 tengine2.3.2 mysql8.0 redis5 process detailed explanation
  • How to implement scheduled backup of MySQL in Linux
  • How to reset the root password in Linux mysql-5.6
  • Use MySQL to open/modify port 3306 and open access permissions in Ubuntu/Linux environment
  • MySQL scheduled backup solution (using Linux crontab)
  • Detailed tutorial on installing MySQL database in Linux environment
  • Linux MySQL root password forgotten solution
  • Detailed tutorial on installing mysql-8.0.20 under Linux
  • How to use MyCat to implement MySQL master-slave read-write separation in Linux

<<:  Modification of time zone problem of MySQL container in Docker

>>:  This article teaches you how to import CSS like JS modules

Recommend

Tomcat maxPostSize setting implementation process analysis

1. Why set maxPostSize? The tomcat container has ...

Vue3 uses axios interceptor to print front-end logs

Table of contents 1. Introduction 2. Use axios in...

Vue implements the frame rate playback of the carousel

This article example shares the specific code of ...

Solve the problem of VScode configuration remote debugging Linux program

Let's take a look at the problem of VScode re...

Implementing shopping cart function based on vuex

This article example shares the specific code of ...

More Features of the JavaScript Console

Table of contents Overview console.log console.in...

WeChat applet to obtain mobile phone number step record

Preface Recently, I encountered such a problem wh...

How to cancel the background color of the a tag when it is clicked in H5

1. Cancel the blue color of the a tag when it is ...

An article to give you a deep understanding of Mysql triggers

Table of contents 1. When inserting or modifying ...

Detailed explanation of JavaScript Proxy object

Table of contents 1. What is Proxy? 2. How to use...

Manually install mysql5.7.10 on Ubuntu

This tutorial shares the process of manually inst...