This article is a mirror article of machine translation, please click here to jump to the original article.

View: 27725|Reply: 4

[Source] Regularly back up remote MySQL databases in Linux environments

[Copy link]
Posted on 9/30/2021 2:42:47 PM | | | |
Scheduled database backup is a must-try for every developer, and regular backup data can solve the problem of accidentally deleting some data, which can be restored to a certain moment and minimize losses.

MySQL provides a convenient tool for exporting database data and files from the command line, mysqldump, which can export databases through the command line.

Review:

mysqldump imports and exports database summaries
https://www.itsvse.com/thread-4353-1-1.html

Use MySQL to automatically schedule backups in a Windows environment
https://www.itsvse.com/thread-7412-1-1.html

[Reprint] Regularly backing up scripts for websites and databases under Linux
https://www.itsvse.com/thread-4428-1-1.html

MySQL database backup and export
https://www.itsvse.com/thread-4004-1-1.html
This article is usedCentOS 7environment, backing up remote databases to the local via mysqldump. If we run the mysqldump command directly, the error will be as follows:

-bash: mysqldump: command not found
An open-source third-party package is recommended here, Mydumper, a high-performance multi-threaded backup and recovery tool for MySQL and Drizzle. Faster than mysqldump backup speed and recovery speed.

GitHub address:The hyperlink login is visible.

The installation command is as follows:

Linux environment basics: the difference between installing el6, el7, and el8 in rpm packages
https://www.itsvse.com/thread-10098-1-1.html
In this way, both mydumper and myloader commands can already be used, mydumper is responsible for exporting, and myloader is responsible for importing, as shown in the figure below:



mydumperParameter explanation

-B, --database The database to be backed up, if not specified, back up all libraries
-T, --tables-list The tables that need to be backed up, the names are separated by commas
-o, --outputdir to back up the directory where the file is output
-s, --statement-size The number of bytes of the insert statement generated by --statement-size is 1000000 by default
-r, --rows When dividing a table into rows, specify the number of block rows, specifying this option will turn off --chunk-filesize
-F, --chunk-filesize When chunking a table by size, the specified block size in MB
-c, --compress compress compress the output file
-e, --build-empty-files if the table data is empty, or it produces an empty file (by default no data only the table structure file)
-x, --regex is the same as the regular expression matching 'db.table'
-i, --ignore-engines ignore storage engines, and use thick partitioning
-m, --no-schemas do not back up table structures
-k, --no-locks do not use temporary shared read-only locks, and using this option will cause data inconsistencies
--less-locking reduces the time it takes to apply locks to InnoDB tables (the mechanics of this pattern are explained in detail below)
-l, --long-query-guard Set the timeout time for long queries that block backups, in seconds, and the default is 60 seconds (mydumper will exit by default after the timeout).
--kill-long-queries kill long queries (without exiting)
-b, --binlogs export binlogs
-D, --daemon enable daemon mode, which backs up the database at certain intervals without interruption
-I, --snapshot-interval dump Snapshot interval time, default 60s, needs to be in daemon mode
-L, --logfile uses the log file name (the log generated by mydumper), and uses standard output by default
--tz-utc across time zones is an option used, not explained
--skip-tz-utc Id
--use-savepoints Use savepoints to reduce lock time caused by metadata collection, which requires SUPER permissions
--success-on-1146           Not increment error count and Warning instead of Critical in case of table doesn't exist
-h, --host The hostname of the connection
-u, --user back up the user used
-p, --password password
-P, --port port
-S, --socket The socket file when using socket communication
-t, --threads The default number of backup threads enabled is 4
-C, --compress-protocol compresses data communicating with mysql
-V, --version displays the version number
-v, --verbose output information pattern, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default to 2
myloaderParameter explanation

-d, --directory folder for the backup file
-q, --queries-per-transaction The number of queries executed per thing is 1000 by default
-o, --overwrite-tables If the table to be restored exists, drop the table first, use this parameter, and back up the table structure when you need to back up
-B, --database The database that needs to be restored
-e, --enable-binlog enables binary logs to restore data
-h, --hosthost
-u, --user restored
-p, --password password
-P, --port port
-S, --socket socket file
-t, --threads restores the number of threads used, the default is 4
-C, --compress-protocol
-V, --version displays the version
-v, --verbose output mode, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default to 2
Test backups

The database export command is as follows:



After execution, mydumper will create a specified directory address that we pass through parameters, which contains a metadata file that records the binary log file name at the backup time and the location where the log was written. Each table has two backup files:database.table-schema.sql a table structure file, and database.table.sql table data file.

Scheduled backups

The reference articles are as follows:

CentOS 7 uses crontab to perform tasks at regular intervals
https://www.itsvse.com/thread-9280-1-1.html
Let's create a new shell script named :backup_uat.sh, as follows:

Grant Execution Permissions:


Add a task

The task is performed every day at 00:10 am



Reload the configuration

(End)





Previous:Linux environment basics: the difference between installing el6, el7, and el8 in rpm packages
Next:RAID Technology Explained - RAID0, RAID1, RAID3, RAID5, RAID6, RAID10 comparison
 Landlord| Posted on 9/30/2021 5:03:15 PM |
Test restoring the database from the backup file

-o, --overwrite-tables If the table to be restored exists, drop the table first, use this parameter, and back up the table structure when you need to back up


This command,Newly created tables and data are not deleted

Posted on 10/2/2021 4:58:15 PM |
Study hard and improve every day
 Landlord| Posted on 10/19/2022 9:07:56 PM |
[Actual combat]. NET/C# implements MySQL database backups based on MySqlBackup.NET
https://www.itsvse.com/thread-10375-1-1.html
Posted on 11/15/2022 6:19:56 PM |
Learn it
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com