{"id":2371,"date":"2016-06-13T13:53:18","date_gmt":"2016-06-13T13:53:18","guid":{"rendered":"http:\/\/kedar.nitty-witty.com\/?p=2371"},"modified":"2023-04-27T09:56:56","modified_gmt":"2023-04-27T09:56:56","slug":"restoring-mysql-database-from-xtrabackup-facepalm-moments","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/restoring-mysql-database-from-xtrabackup-facepalm-moments","title":{"rendered":"MySQL database restore issues using xtrabackup &#8211; facepalm moments"},"content":{"rendered":"\n<p>In this post we&#8217;ll see some facepalm moments during MySQL database restore from Percona Xtrabackup.&nbsp; I think: &#8220;To mistake is Homo-sapiens, to learn from them is Homo-sapiens-sapiens.&#8221;<\/p>\n\n\n\n<p>A typical way to restore MySQL backup from Xtrabackup involves following steps:<\/p>\n\n\n\n<p>&#8211; Ship or stream backup to destination.<br>&#8211; Perform extraction of the compressed database backup.<br>&#8211; Perform apply-log step to prepare the backup.<br>&#8211; Bring up MySQL.<br>&#8211; Configure replication (if that&#8217;s required).<\/p>\n\n\n\n<p>We have a lot of documentation &amp; blogs explaining that,&nbsp; but let&#8217;s see how our MySQL DBA enjoyed the facepalm moments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1) A quick MySQL backup restore.<\/h3>\n\n\n\n<p>Scenario: Our DBA received an urgent request, need to<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>work fast! He&#8217;s done taking fresh backup or moving recent backup to destination. He is done with backup extracting and that&#8217;s it! Time to start MySQL and then we hear him saying.<\/p>\n\n\n\n<p>MySQL DBA: &#8220;Error!! D&#8217;oh&#8221;<\/p>\n\n\n\n<p>Q : Did you apply-log?<br>MySQL DBA: mysql-facepalm<\/p>\n\n\n\n<p>Take away:<\/p>\n\n\n\n<p>&#8211; Apply-log step is where xtrabackup prepares the backup. In this step the transactions from xtrabackup_logfile are applied to the backup and also the iblog files are created.<\/p>\n\n\n\n<p>&#8211; Make sure we do apply-log before bringing up mysql.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2) Can you quickly move this MySQL backup file to destination?<\/h3>\n\n\n\n<p>Scenario: On some typical Monday our MySQL DBA is on a database restore project. He started the screen session and started scp of some large backup file to its destination. He returned from with a coffee and we heard him saying&#8230;<\/p>\n\n\n\n<p>MySQL DBA: What! Disk full&#8230;usage 100%!!<\/p>\n\n\n\n<p>Q: Did you check the disk space before you begin?<br>MySQL DBA: mysql-facepalm<\/p>\n\n\n\n<p>&#8211; This is obvious that the destination should have sufficient space to hold the data files else a disk full is guaranteed!<\/p>\n\n\n\n<p>&#8211; Have a good estimate of backup file(s) being transmitted. Whether you&#8217;re extracting a backup or you&#8217;re streaming a backup; make sure you&#8217;re aware of disk requirement for the activity.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3) Let&#8217;s setup a slave for this host:<\/h3>\n\n\n\n<p>Scenario: Well well&#8230; DBA is having fun again. He crossed all the milestones of Xtrabackup MySQL Restore and about to conclude the activity. He&#8217;s now progressing to setup the MySQL replication using co-ordinates in xtrabackup_slave_info file.<\/p>\n\n\n\n<p>MySQL DBA: &#8220;start slave; show slave status; What? Binary log missing?!!? Master purged it?&#8221;<\/p>\n\n\n\n<p>Q: Did you check expire-logs-days before starting the restore?<br>MySQL DBA:: mysql-facepalm<\/p>\n\n\n\n<p>&#8211; This is huge time-waster&#8230; Master purged and slave couldn&#8217;t find the binlog to replicate from.<br>&#8211; Make sure we always estimate the time for restore and master should retain the binary-logs until new host starts and can catchup.<\/p>\n\n\n\n<p>The xtrabackup_slave_info file stores the binary log coordinates with master name as a CHANGE MASTER TO command. Important to note that this is logged only if you&#8217;re using &#8211;slave-info option. To avoid facepalm moments, make sure to check what&#8217;s your backup command as well. (Our MySQL DBA luckily did not face this one yet)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4) Yet another restore MySQL database. (This is good one, pay attention)<\/h3>\n\n\n\n<p>Scenario: Our DBA is having hardtime now. He&#8217;s extracted his backup to the MySQL data directory, finished apply-log step but then couldn&#8217;t start MySQL &amp; sees following!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>150522&nbsp; 7:34:18 InnoDB: highest supported file format is Barracuda.<br>InnoDB: ##########################################################<br>InnoDB:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WARNING!<br>InnoDB: The log sequence number in ibdata files is higher<br>InnoDB: than the log sequence number in the ib_logfiles! Are you sure<br>InnoDB: you are using the right ib_logfiles to start up the database?<br>InnoDB: Log sequence number in ib_logfiles is 47671324554413, log<br>InnoDB: sequence numbers stamped to ibdata file headers are between<br>InnoDB: 65257024335884 and 65257024335884.<br>InnoDB: ##########################################################<br>InnoDB: The log sequence number in ibdata files does not match<br>InnoDB: the log sequence number in the ib_logfiles!<br>150522&nbsp; 7:34:18&nbsp; InnoDB: Database was not shut down normally!<\/code><\/pre>\n\n\n\n<p>MySQL DBA: &#8220;Now that&#8217;s what we call an error but how! All steps I&#8217;m doing correct&#8230;&#8221;<\/p>\n\n\n\n<p>Q: Where are your iblogs?<br>A: hmm let me check&#8230; \ud83d\ude42<\/p>\n\n\n\n<p>&#8211; Right&#8230; This scenario is prone to happen especially when we have different data-directory layout. By default iblogs will go directly into MySQL datadir.<br>Xtrabackup creates backup-my.cnf file which includes the options of configuration file used in backup.<br>&#8211; Consider that destination server stores iblog files in a different directory unlike source server, then this is bound to happen.<br>&#8211; You can resolve these in two ways: First is to include innodb_log_group_home_dir to backup-my.cnf before apply-log. Alternatively you may continue with apply-log step and then move newly generated ib_logfiles to proper innodb_log_group_home_dir.<\/p>\n\n\n\n<p>There must be many such things our MySQL DBA can hint us but we&#8217;ll learn more about them next time.<\/p>\n\n\n\n<p>In this post we saw possibilities of failure during a MySQL database restore from a backup (taken from Xtrabackup):<br>&#8211; Performing incomplete MySQL restore steps by missing to prepare backup (apply-log)<br>&#8211; Performing activity without size estimates and feasibility<br>&#8211; Missing to check a related but important detail which totally derail the project.<br>&#8211; Ignoring the database (installation) architecture.<br>Well we can have a single solution to all the above problems. No kidding we can&#8230; and that is&#8230;? Action plan!<\/p>\n\n\n\n<p>Yes, action plans are really important part of any implementation. It&#8217;s rather essential part which outlines the exact steps to achieve the goal.<\/p>\n\n\n\n<p>It&#8217;s not always your technical ability but ignorance of action plan or missing small steps which causes you a big trouble and brings you MySQL facepalm moments.<\/p>\n\n\n\n<p>I&#8217;ll share more facepalms later; in the mean time share if you know some! It&#8217;s learning for sure \ud83d\ude42<\/p>\n\n\n\n<p>PS: noted the date of error above, this article was pending since then.<\/p>\n","protected":false},"excerpt":{"rendered":"Learning from facepalm moments of a MySQL database restore from Percona Xtrabackup.\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8,377],"tags":[459,562,561,563,366,560,559],"class_list":{"0":"post-2371","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-mysql","7":"category-mysql-articles","8":"tag-backup-and-restore","9":"tag-dba-restore","10":"tag-facepalm-moments","11":"tag-percona-xtrabackup-database-restore","12":"tag-restore","13":"tag-restore-database","14":"tag-restore-xtrabackup"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/2371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=2371"}],"version-history":[{"count":8,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/2371\/revisions"}],"predecessor-version":[{"id":2833,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/2371\/revisions\/2833"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=2371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=2371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=2371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}