Top Banner
Copying your databases Percona Live 2021 Nicolai Plum – Booking.com Database Engineering
29

Copying your databases

Feb 21, 2023

Download

Documents

Khang Minh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Copying your databases

Copying your databases

Percona Live 2021Nicolai Plum – Booking.com Database Engineering

Page 2: Copying your databases

TopicsWhen and why?

Where from?MySQL-side methodsStorage-side methods

Comparisons and Recommendations

Page 3: Copying your databases

MySQL at Booking.com● In use 15+ years● Thousands of instances● Hundreds of replication chains● Data storage across our business

Page 4: Copying your databases

Database copies – Why?● New instances ● Replacements● Upgrades● Backups

Page 5: Copying your databases

Database copies – Where From?

Page 6: Copying your databases

Primary master

Page 7: Copying your databases

Intermediate/standby replica

Page 8: Copying your databases

Shared replica serving users

Page 9: Copying your databases

Dedicated replica

Page 10: Copying your databases

Comparison

Efficiency(cost saving)

Speed UserImpact

Primary Master High Medium HighIntermediate / standby

High High Medium

Existing replica High Medium HighDedicated replica Low High Low

Page 11: Copying your databases

Recommendation● First choice: Dedicated replica● Second choice: Intermediate/standby

● For creating new chains: Primary master

Page 12: Copying your databases

MySQL-side methodsOnline

mysqldump stylextrabackup styleNative Cloning

Offlinefile rsyncZFS send/receive

Backup & restore

Page 13: Copying your databases

mysqldump / mariadump● SQL: DDL + DML + GTID● Very flexible● Including version downgrade and load to other

vendors● Very slow● The last resort; don't even bother automating

Page 14: Copying your databases

xtrabackup / mariabackup● Tablespaces + log● "prepare" after copy● No downgrade in MySQL 8, MariaDB 10.5● Fast enough for many uses

Page 15: Copying your databases

Native Cloning● Oracle MySQL 8 only● Exact version match only● Simple command via SQL interface● 2-3 times faster than xtrabackup

Page 16: Copying your databases

File copy● Create consistent copy of database files● Shutdown for snapshot or copy

● Copy using rsync (daemon), pigz, …● or filesystem tools – ZFS send/receive

● Transport efficiency is a factor here

Page 17: Copying your databases

Storage-side methods● Command storage to make snapshot of

data● Copy/clone/restore snapshot● Start new instance● Profit!

Page 18: Copying your databases
Page 19: Copying your databases

Inconsistent snapshot

Page 20: Copying your databases

Consistent snapshot

Page 21: Copying your databases

Shutdown for copy?● Have you analysed the storage system in

great detail?● Do you feel lucky?● No?● Then shutdown MySQL for snapshot.

Page 22: Copying your databases

Advantages of storage copy● Fast (usually)● Features are already available (with most

modern storage)● Can be simpler than host copy

Page 23: Copying your databases

Limitations?● Available immediately?● Performance while copying?● Ancestor volume must continue to exist?● Limited number of descendents?● Concurrency limits?● Copy between storage clusters?● Management complexity?

Page 24: Copying your databases

Backup and restore● You have backup, and also restore.● Restore is…● Not scalable (restore a backup to one target only)● Often not very fast● Often not made for intensive use 24/7

● Useful secondary copying method

Page 25: Copying your databases

Concurrency● Hardware limits● 6Gb/s SATA, 10Gb/s Ethernet

● Mutually incompatible methods●Online vs offline

● Snapshot freshness● Replicating during snap copying works fine

Page 26: Copying your databases

After copying data● Attach the volume to server instance, if needed● Change server_id and server_uuid● Set up replication as needed● Use GTID and AUTO_POSITION● Or join to a group or cluster

● System automation setup● Register with monitoring & metrics

Page 27: Copying your databases

ComparisonsFlexible(version)

Speed Online(source)?

Recommendation

MySQLdump Very Very slow Yes Last resortxtrabackup Yes * Medium Yes First choiceNative No * Fast Yes Handy extraFile copy Yes * Fast No First choiceStorage copy

Yes * Very fast (or maybe slow)

No If available, first choice

Restore Yes Slow Varies Second choice* Remember no downgrades on Oracle MySQL 8, Percona 8, and MariaDB 10.5

Page 28: Copying your databases

Recommendation● Online copy will sometimes be necessary● Implement automation for several options:● First choices: xtrabackup, File copy, Storage copy

(if available)● Second choices: Native, Restore● Do not:● Assume storage cloning is always possible● Rely on Native alone (makes upgrades painful)