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

MySQL-8.0.26 Configuration Graphics Tutorial

Preface: Recently, the company project changed th...

JavaScript commonly used array deduplication actual combat source code

Array deduplication is usually encountered during...

The reason why MySQL uses B+ tree as its underlying data structure

We all know that the underlying data structure of...

Solution to the problem that elements with negative z-index cannot be clicked

I was working on a pop-up ad recently. Since the d...

JavaScript's unreliable undefined

undefined In JavaScript, if we want to determine ...

Use of Linux ipcs command

1. Command Introduction The ipcs command is used ...

Tutorial on how to modify the root password in MySQL 5.7

Version update, the password field in the origina...

Docker practice: Python application containerization

1. Introduction Containers use a sandbox mechanis...

The difference between html form submission action and url jump to actiond

The action of the form is different from the URL j...

MySQL database table partitioning considerations [recommended]

Table partitioning is different from database par...

Linux uses bond to implement dual network cards to bind a single IP sample code

In order to provide high availability of the netw...

What can I use to save you, my table (Haiyu Blog)

Tables once played a very important role in web p...

Introduction to fourteen cases of SQL database

Data Sheet /* Navicat SQLite Data Transfer Source...