Windows MySql incremental backup, full backup Pit Road

1 Introduction

This week the company gave me a task, Mysql database backup in charge of the project, because the project on-line data is a big problem, the biggest problem is the problem of data backup is particularly important at this time,

The company's project is the idea: within the project system settings you can check the full and incremental backups, choose backup within a specified time, you can also choose to manually back up

My idea: the need for a backup command mysql wrote bat batch file which, according to the back-end timer to call Java methods, method calls bat batch file!

 

2. full backup

A full backup with incremental backups is much simpler, because the generated SQL file is, you can directly into the main pit mining or incremental backups

1. The number of projects grows and more and more data, if only a simple global backup, but also take up disk is time consuming

2. can be considered a full backup weekly backup, incremental backup once a day

 

How to back up multiple tables?

A: mysqldump -u -p User Database Table 1 Table 2 Table ...... N> Backup File Path

How to back up a database?

A: mysqldump -u user -p -B Database> Backup file path

How to back up multiple databases?

A: mysqldump -u user -p -B 1 Library Library Library 2 ...... N> Backup File Path

How to back up all your data?

A: mysqldump -u user -p -A> Backup File Path

 

 

 

After a good backup SQL files

Importing files 3.SQL

source sql file path

 

4. Pit Road incremental backups

4.1 version of the problem (pit)

I use mysql is phpStyle before that comes, in its version 5.56 of the way, there is no built-in command can generate a log file of mysqlbinlog command 

Error try: go online to download a version mysqlbinlog but did not consider the issue, although you can generate a binary file, but the guide does not go! ! ! failure

 

4.2 installed my.ini configuration file can not be found after a mysql 8.0 version!

Try: Baidu found, mysql 8.0 version that has opened the logs, we do not need to modify the configuration file mysql

Reference: https://blog.csdn.net/zone_/article/details/81321431

 

4.3 exported mysql binary log file does not recognize say it is not a binary file (TM you kidding me ????)

1. First, find out the latest log file name

2. Use the command to export! (I have been here a binary directory changed, has not changed the log files are stored in: C: \ ProgramData \ MySQL \ MySQL Server 8.0 \ Data) ( hidden directory !!!!!!)

 

Try: Use the command Export: mysqlbinlog -uroot -proot --read-from-remote-server binlog.000003> e: \ backup \ binlog.000003

 

1. Export the file does not actually open garbage! ! Amaze

2. Try to import, forget the guide does not go

 

Try to SQL file binary file into something, try to import!

1.尝试导出 mysqlbinlog --no-defaults --base64-output=decode-rows -v binlog.000004 --result-file=e:\backup\123.sql

2. Try to import: source e: /backup/123.sql 

 

failure! ! ! ! Mentality burst

 

The ultimate esoteric!

1. ideas: Use bat batch copy out the binary file and then import it?

2. Try to find where there is a log file is a hidden directory, cmd window simply fewer than, Ever! ! ! !

 

Mysql modify the configuration file, save it to generate a binary file that I copied elsewhere

 

Reference: https://blog.csdn.net/The_Beetles/article/details/89553653

 

The following two scripts contribution bat batch file, easy to use

 

::--------------全量备份mysql数据库---------------
::服务器数据库ip 用户名 密码 申明需要备份的数据库
set suser=root
set suserpwd=root
set backdatabase=test

::当前系统日期 20160309
set now=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%

::备份文件夹
set backup=backup
if not exist %backup% md %backup%

::以日期命名的文件夹
set nowfile=%backup%\%now%
if not exist %nowfile% md %nowfile%

::开始备份
mysqldump -u%suser% -p%suserpwd% --single-transaction --skip-triggers --skip-lock-tables --master-data=2 --force  -B %backdatabase%>%nowfile%\%backdatabase%.sql

exit

  

@echo off

::服务器数据库ip 用户名 密码
set suser=root
set suserpwd=root
::mysql 二进制日志文件存放的位置
set filePath= E:\mysql\Data ::当前系统日期 20160309 set now=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2% ::备份文件夹 set backup=backup if not exist %backup% md %backup% ::以日期命名的文件夹 set nowfile=%backup%\%now%-Increase if not exist %nowfile% md %nowfile% ::前一次日志文件名 set binlog=%nowfile%\binlog.txt mysql -u%suser% -p%suserpwd% -e "show master status"|findstr -B binlog.>%binlog% ::处理日志文件名 只取binlog.001365 复制到目标文件夹 FOR /F "delims= " %%i in (%binlog%) do copy %filePath%\%%i %nowfile% ::刷新日志产生新的日志 mysqladmin -u%suser% -p%suserpwd% flush-logs exit

 

长路漫漫!采坑为伴

 

Guess you like

Origin www.cnblogs.com/ChromeT/p/11074479.html
Recommended