Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created July 15, 2017 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahemoff/f88f35887c33c5cf089c7ffa6fe49895 to your computer and use it in GitHub Desktop.
Save mahemoff/f88f35887c33c5cf089c7ffa6fe49895 to your computer and use it in GitHub Desktop.
MySQL backup for replication

Put database in read-only mode and capture master log position:

mysqL> FLUSH TABLES WITH READ LOCK; SET GLOBAL read_only = ON; SHOW MASTER STATUS;`

Copy entire mysql data folder:

bash> cp -r /var/lib/mysql /home/me/prod_varlibmysql20170715 ; date`

When copy is complete, immediately turn off read-only mode:

mysqL> SET GLOBAL read_only = OFF; UNLOCK TABLES;`

Rename backup file to include master position, this makes it easier and safer to setup the slave:

bash> mv /home/me/prod_varlibmysql20170715 /home/me/prod_mysql-bin.000014_64936180_varlibmysql20170715
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment