{"id":2717,"date":"2010-08-03T08:45:29","date_gmt":"2010-08-03T06:45:29","guid":{"rendered":"http:\/\/code.openark.org\/blog\/?p=2717"},"modified":"2010-08-12T16:15:38","modified_gmt":"2010-08-12T14:15:38","slug":"tips-for-taking-mysql-backups-using-lvm","status":"publish","type":"post","link":"https:\/\/code.openark.org\/blog\/mysql\/tips-for-taking-mysql-backups-using-lvm","title":{"rendered":"Tips for taking MySQL backups using LVM"},"content":{"rendered":"<p>LVM uses copy-on-write to implement snapshots. Whenever you&#8217;re writing data to some page, LVM copies the original page (the way it looked like when the snapshot was taken) to the snapshot volume. The snapshot volume must be large enough to accommodate all pages written to for the duration of the snapshot&#8217;s lifetime. In other words, you must be able to copy the data somewhere outside (tape, NFS, rsync, etc.) in less time than it would take for the snapshot to fill up.<\/p>\n<p>While LVM allows for hot backups of MySQL, it still poses an impact on the disks. An LVM snapshot backup may not go unnoticed by the MySQL users.<\/p>\n<p>Some general guidelines for making life easier with LVM backups follow.<\/p>\n<h4>Lighter, longer snapshots<\/h4>\n<p>If you&#8217;re confident that you have enough space on your snapshot volume, you may take the opportunity to make for a <em>longer<\/em> backup time. Why? Because you would then be able to reduce the stress from the file system. Use <strong>ionice<\/strong> when copying your data from the snapshot volume:<\/p>\n<blockquote>\n<pre>ionice -c 2 cp -R \/mnt\/mysql_snapshot \/mnt\/backup\/daily\/20100719\/\r\n<\/pre>\n<\/blockquote>\n<p><em>[Update: this is only on the cfq I\/O scheduler; thanks, Vojtech]<\/em><\/p>\n<h4>Are you running out of space?<\/h4>\n<p>Monitor snapshot&#8217;s allocated size: if there&#8217;s just one snapshot, do it like this:<!--more--><\/p>\n<blockquote>\n<pre>lvdisplay | grep Allocated\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Mon Jul 19 09:51:29 2010\r\n\r\n Allocated to snapshot\u00a0 3.63%\r\n<\/pre>\n<\/blockquote>\n<p>Don&#8217;t let it reach 100%.<\/p>\n<h4>Avoid running out of space<\/h4>\n<p>To make sure you don&#8217;t run out of snapshot allocated size, stop all administrative scripts.<\/p>\n<ul>\n<li>Are you running your weekly purging of old data? You will be writing a lot of pages, and all will have to fit in the snapshot.<\/li>\n<li>Building your reports? You may be creating large temporary tables; make sure these are not on the snapshot volume.<\/li>\n<li>Rebuilding your Sphinx fulltext index? Make sure it is not on the snapshot volume, or postpone till after backup.<\/li>\n<\/ul>\n<p>You will gain not only snapshot space, but also faster backups.<\/p>\n<h4>Someone did the job before you<\/h4>\n<p>Use <a href=\"http:\/\/www.lenzg.net\/mylvmbackup\/\">mylvmbackup<\/a>: the MySQL LVM backup script by Lenz Grimmer. Or do it manually: follow this old-yet-relevant <a href=\"http:\/\/www.mysqlperformanceblog.com\/2006\/08\/21\/using-lvm-for-mysql-backup-and-replication-setup\/\">post<\/a> by Peter Zaitsev.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LVM uses copy-on-write to implement snapshots. Whenever you&#8217;re writing data to some page, LVM copies the original page (the way it looked like when the snapshot was taken) to the snapshot volume. The snapshot volume must be large enough to accommodate all pages written to for the duration of the snapshot&#8217;s lifetime. In other words, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[5],"tags":[7,119,50],"class_list":["post-2717","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-backup","tag-linux","tag-scripts"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2bZZp-HP","_links":{"self":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/2717","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/comments?post=2717"}],"version-history":[{"count":15,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/2717\/revisions"}],"predecessor-version":[{"id":2837,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/2717\/revisions\/2837"}],"wp:attachment":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/media?parent=2717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/categories?post=2717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/tags?post=2717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}