<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="replication-solutions-backups-rawdata">
      </a>
      19.4.1.2 Backing Up Raw Data from a Replica
     </h4>
    </div>
   </div>
  </div>
  <p>
   To guarantee the integrity of the files that are copied, backing
        up the raw data files on your MySQL replica should take place
        while your replica server is shut down. If the MySQL server is
        still running, background tasks may still be updating the
        database files, particularly those involving storage engines
        with background processes such as
   <code class="literal">
    InnoDB
   </code>
   .
        With
   <code class="literal">
    InnoDB
   </code>
   , these problems should be
        resolved during crash recovery, but since the replica server can
        be shut down during the backup process without affecting the
        execution of the source it makes sense to take advantage of this
        capability.
  </p>
  <p>
   To shut down the server and back up the files:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Shut down the replica MySQL server:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa78023725"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">mysqladmin</span> shutdown</code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      Copy the data files. You can use any suitable copying or
            archive utility, including
      <span class="command">
       <strong>
        cp
       </strong>
      </span>
      ,
      <span class="command">
       <strong>
        tar
       </strong>
      </span>
      or
      <span class="command">
       <strong>
        WinZip
       </strong>
      </span>
      . For
            example, assuming that the data directory is located under
            the current directory, you can archive the entire directory
            as follows:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa27904775"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">tar</span> cf /tmp/dbbackup<span class="token punctuation">.</span>tar <span class="token punctuation">.</span>/data</code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      Start the MySQL server again. Under Unix:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa42391753"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">mysqld_safe</span> &amp;</code></pre>
     </div>
     <p>
      Under Windows:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa29132836"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">C:\&gt;</span> <span class="token atrule">"C:\Program Files\MySQL\MySQL Server 8.4\bin\mysqld"</span></code></pre>
     </div>
    </li>
   </ol>
  </div>
  <p>
   Normally you should back up the entire data directory for the
        replica MySQL server. If you want to be able to restore the data
        and operate as a replica (for example, in the event of failure
        of the replica), in addition to the data, you need to have the
        replica's connection metadata repository and applier metadata
        repository, and the relay log files. These items are needed to
        resume replication after you restore the replica's data.
        Assuming tables have been used for the replica's connection
        metadata repository and applier metadata repository (see
   <a class="xref" href="replica-logs.html" title="19.2.4 Relay Log and Replication Metadata Repositories">
    Section 19.2.4, “Relay Log and Replication Metadata Repositories”
   </a>
   ), which is the default in MySQL
        8.4, these tables are backed up along with the data
        directory. If files have been used for the repositories, which
        is deprecated, you must back these up separately. The relay log
        files must be backed up separately if they have been placed in a
        different location to the data directory.
  </p>
  <p>
   If you lose the relay logs but still have the
   <code class="filename">
    relay-log.info
   </code>
   file, you can check it to
        determine how far the replication SQL thread has executed in the
        source's binary logs. Then you can use
   <a class="link" href="change-replication-source-to.html" title="15.4.2.2 CHANGE REPLICATION SOURCE TO Statement">
    <code class="literal">
     CHANGE REPLICATION SOURCE TO
    </code>
   </a>
   with
        the
   <code class="literal">
    SOURCE_LOG_FILE
   </code>
   and
   <code class="literal">
    SOURCE_LOG_POS
   </code>
   options to tell the replica to
        re-read the binary logs from that point. This requires that the
        binary logs still exist on the source server.
  </p>
  <p>
   If your replica is replicating
   <a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement">
    <code class="literal">
     LOAD
        DATA
    </code>
   </a>
   statements, you should also back up any
   <code class="filename">
    SQL_LOAD-*
   </code>
   files that exist in the
        directory that the replica uses for this purpose. The replica
        needs these files to resume replication of any interrupted
   <a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement">
    <code class="literal">
     LOAD DATA
    </code>
   </a>
   operations. The
        location of this directory is the value of the system variable
   <a class="link" href="replication-options-replica.html#sysvar_replica_load_tmpdir">
    <code class="literal">
     replica_load_tmpdir
    </code>
   </a>
   . If the
        server was not started with that variable set, the directory
        location is the value of the
   <a class="link" href="server-system-variables.html#sysvar_tmpdir">
    <code class="literal">
     tmpdir
    </code>
   </a>
   system variable.
  </p>
 </div>
 <br/>
</div>
