<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Back-up and Restore — Bazaar 2.6.0 documentation</title> <link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '2.6.0', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <link rel="shortcut icon" href="../_static/bzr.ico"/> <link rel="top" title="Bazaar 2.6.0 documentation" href="../index.html" /> <link rel="up" title="Bazaar System Administrator’s Guide" href="index.html" /> <link rel="next" title="Upgrades" href="upgrade.html" /> <link rel="prev" title="Security" href="security.html" /> </head> <body> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="upgrade.html" title="Upgrades" accesskey="N">next</a></li> <li class="right" > <a href="security.html" title="Security" accesskey="P">previous</a> |</li> <li><a href="http://bazaar.canonical.com/"> <img src="../_static/bzr icon 16.png" /> Home</a> | </li> <a href="http://doc.bazaar.canonical.com/en/">Documentation</a> | </li> <li><a href="../index.html">Table of Contents (2.6.0)</a> »</li> <li><a href="index.html" accesskey="U">Bazaar System Administrator’s Guide</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="back-up-and-restore"> <h1>Back-up and Restore<a class="headerlink" href="#back-up-and-restore" title="Permalink to this headline">¶</a></h1> <p>Backing up Bazaar branches can be done in two different ways. If an existing filesystem-based backup scheme already exists, then it can easily be used where the Bazaar branches reside. Alternately, Bazaar itself can be used to mirror the desired branches to or from another location for backup purposes.</p> <div class="section" id="filesystem-backups"> <h2>Filesystem Backups<a class="headerlink" href="#filesystem-backups" title="Permalink to this headline">¶</a></h2> <p>Bazaar transactions are atomic in the sense that the disk format is such that it is in a valid state at any instant in time. However, for a backup process that takes a finite amount of time to complete, it is possible to have inconsistencies between different on-disk structures when backing up a live branch or repository. (Bazaar itself manages this concurrency issue by only <em>reading</em> those structures in a well-defined order.) Tools such as LVM that allow instantaneous snapshots of the contents of a disk can be used to take filesystem backups of live Bazaar branches and repositories.</p> <p>For other backup methods, it is necessary to take the branch or repository offline while the backup is being done in order to guarantee consistency between the various files that comprise a Bazaar branch’s history. This requirement can be alleviated by using Bazaar as its own backup client, since it follows an order for reading that is designed to manage concurrent access (see the next section for details). Depending on the different access methods that are being used for a branch, there are different ways to take the branch “offline”. For <tt class="docutils literal"><span class="pre">bzr+ssh://</span></tt> access, it is possible to temporarily change the filesystem permissions to prevent write access from any users. For <tt class="docutils literal"><span class="pre">http://</span></tt> access, changing permissions, shutting down the HTTP server or switching the server to a separate configuration that disallows access are all possible ways to take a branch offline for backup. Finally, for direct filesystem access, it is necessary to make the branch directories un-writable.</p> <p>Because this sort of downtime can be very disruptive, we strongly encourage using Bazaar itself as a backup client, where branches are copied and updated using Bazaar directly.</p> </div> <div class="section" id="bazaar-as-its-own-backup"> <h2>Bazaar as its own backup<a class="headerlink" href="#bazaar-as-its-own-backup" title="Permalink to this headline">¶</a></h2> <p>The features that make Bazaar a good distributed version control system also make it a good choice for backing itself up. In particular, complete and consistent copies of any branch can easily be obtained with the <tt class="docutils literal"><span class="pre">branch</span></tt> and <tt class="docutils literal"><span class="pre">pull</span></tt> commands. As a result, a backup process can simply run <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">pull</span></tt> on a copy of the main branch to fully update that copy. If this backup process runs periodically, then the backups will be as current as the last time that <tt class="docutils literal"><span class="pre">pull</span></tt> was run. (This is in addition to the fact that revisions are immutable in Bazaar so that a prior revision of a branch is always recoverable from that branch when the revision id is known.)</p> <p>As an example, consider a separate backup server that stores backups in <tt class="docutils literal"><span class="pre">/var/backup</span></tt>. On that server, we could initially run</p> <div class="highlight-python"><pre>$ cd /var/backup $ bzr branch bzr+ssh://server.example.com/srv/bzr/trunk $ bzr branch bzr+ssh://server.example.com/srv/bzr/feature-gui</pre> </div> <p>to create the branches on the backup server. Then, we could regularly (for example from <tt class="docutils literal"><span class="pre">cron</span></tt>) do</p> <div class="highlight-python"><pre>$ cd /var/backup/trunk $ bzr pull # the location to pull from is remembered $ cd ../var/backup/feature-gui $ bzr pull # again, the parent location is remembered</pre> </div> <p>The action of pulling from the parent for all branches in some directory is common enough that there is a plugin to do it. The <a class="reference external" href="http://launchpad.net/bzrtools">bzrtools</a> plugin contains a <tt class="docutils literal"><span class="pre">multi-pull</span></tt> command that does a <tt class="docutils literal"><span class="pre">pull</span></tt> in all branches under a specified directory.</p> <p>With this plugin installed, the above periodically run commands would be</p> <div class="highlight-python"><pre>$ cd /var/backup $ bzr multi-pull</pre> </div> <p>Note that <tt class="docutils literal"><span class="pre">multi-pull</span></tt> does a pull in <em>every</em> branch in the specified directory (the current directory by default) and care should be taken that this is the desired effect. A simple script could also substitute for the multi-pull command while also offering greater flexibility.</p> <div class="section" id="bound-branch-backups"> <h3>Bound Branch Backups<a class="headerlink" href="#bound-branch-backups" title="Permalink to this headline">¶</a></h3> <p>When <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">pull</span></tt> is run regularly to keep a backup copy up to date, then it is possible that there are new revisions in the original branch that have not yet been pulled into the backup branch. To alleviate this problem, we can set the branches up so that new revisions are <em>pushed</em> to the backup rather than periodically pulling. One way to do this is using Bazaar’s concept of bound branches, where a commit in one branch happens only when the same commit succeeds in the branch to which it is <cite>bound</cite>. As a push-type technology, it is set up on the server itself rather than on the backup machine. For each branch that should be backed up, you just need to use the <tt class="docutils literal"><span class="pre">bind</span></tt> command to set the URL for the backup branch. In our example, we first need to create the branches on the backup server (we’ll use <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">push</span></tt>, but we could as easily have used <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">branch</span></tt> from the backup server)</p> <div class="highlight-python"><pre>$ cd /srv/bzr/projectx/trunk $ bzr push bzr+ssh://backup.example.com/var/backup/trunk $ cd ../feature-gui $ bzr push bzr+ssh://backup.example.com/var/backup/feature-gui</pre> </div> <p>and then we need to bind the main branches to their backups</p> <div class="highlight-python"><pre>$ cd ../trunk $ bzr bind bzr+ssh://backup.example.com/var/backup/trunk $ cd ../feature-gui $ bzr bind bzr+ssh://backup.example.com/var/backup/feature-gui</pre> </div> <p>A branch can only be bound to a single location, so multiple backups cannot be created using this method.</p> <p>Using the <a class="reference external" href="http://launchpad.net/bzr-automirror">automirror</a> plugin mentioned under <a class="reference external" href="hooks-plugins.html">Hooks and Plugins</a>, one can also make a push-type backup system that more naturally handles mutliple backups. Simply set the <tt class="docutils literal"><span class="pre">post_commit_mirror</span></tt> option to multiple URLs separated by commas. In order to backup to the backup server and a remote location, one could do</p> <div class="highlight-python"><pre>$ cd /srv/bzr/trunk $ echo "post_commit_mirror=bzr+ssh://backup.example.com/var/backup/trunk,\ bzr+ssh://offsite.example.org/projectx-corp/backup/trunk" >> .bzr/branch/branch.conf $ cd ../feature-gui $ echo "post_commit_mirror=bzr+ssh://backup.example.com/var/backup/feature-gui,\ bzr+ssh://offsite.example.org/projectx-corp/backup/feature-gui" >> .bzr/branch/branch.conf</pre> </div> <p>As for any push-type backup strategy that maintains consistency, the downside of this method is that all of the backup commits must succeed before the initial commit can succeed. If there is a many mirror branches or if the bound branch has a slow network connection, then the delay in the original commit may be unacceptably long. In this case, pull-type backups, or a mixed system may be preferable.</p> </div> </div> <div class="section" id="restoring-from-backups"> <h2>Restoring from Backups<a class="headerlink" href="#restoring-from-backups" title="Permalink to this headline">¶</a></h2> <div class="section" id="checking-backup-consistency"> <h3>Checking backup consistency<a class="headerlink" href="#checking-backup-consistency" title="Permalink to this headline">¶</a></h3> <p>Many a system administrator has been bitten by having a backup process, but when it came time to restore from backups, finding out that the backups themselves were flawed. As such, it is important to check the quality of the backups periodically. In Bazaar, there are two ways to do this: using the <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">check</span></tt> command and by simply making a new branch from the backup. The <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">check</span></tt> command goes through all of the revisions in a branch and checks them for validity according to Bazaar’s internal invariants. Since it goes through every revision, it can be quite slow for large branches. The other way to ensure that the backups can be restored from is to perform a test restoration. This means performing the restoration process in a temporary directory. After the restoration process, <tt class="docutils literal"><span class="pre">bzr</span> <span class="pre">check</span></tt> may again be relevant for testing the validity of the restored branches. The following two sections present two restoration recipes.</p> </div> <div class="section" id="restoring-filesystem-backups"> <h3>Restoring Filesystem Backups<a class="headerlink" href="#restoring-filesystem-backups" title="Permalink to this headline">¶</a></h3> <p>There are many different backup tools with different ways of accessing the backup data, so we can’t cover them all here. What we will say is that restoring the contents of the <tt class="docutils literal"><span class="pre">/srv/bzr</span></tt> directory completely will restore all branches stored there to their state at the time of the backup (see <a class="reference internal" href="#filesystem-backups">Filesystem Backups</a> for concerns on backing up live branches.) For example, if the backups were mounted at <tt class="docutils literal"><span class="pre">/mnt/backup/bzr</span></tt> then we could restore using simply:</p> <div class="highlight-python"><pre>$ cd /srv $ mv bzr bzr.old $ cp -r /mnt/backup/bzr bzr</pre> </div> <p>Of course, to restore only a single branch from backup, it is sufficient to copy only that branch. Until the restored backup has been successfully used in practice, we recommend keeping the original directory available.</p> </div> <div class="section" id="restoring-bazaar-based-backups"> <h3>Restoring Bazaar-based Backups<a class="headerlink" href="#restoring-bazaar-based-backups" title="Permalink to this headline">¶</a></h3> <p>In order to restore from backup branches, we can simply branch them into the appropriate location:</p> <div class="highlight-python"><pre>$ cd /srv $ mv bzr bzr.old $ cd bzr $ bzr branch bzr+ssh://backup.example.com/var/backup/trunk $ bzr branch bzr+ssh://backup.example.com/var/backup/feature-gui</pre> </div> <p>If there are multiple backups, then change the URL above to restore from the other backups.</p> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Back-up and Restore</a><ul> <li><a class="reference internal" href="#filesystem-backups">Filesystem Backups</a></li> <li><a class="reference internal" href="#bazaar-as-its-own-backup">Bazaar as its own backup</a><ul> <li><a class="reference internal" href="#bound-branch-backups">Bound Branch Backups</a></li> </ul> </li> <li><a class="reference internal" href="#restoring-from-backups">Restoring from Backups</a><ul> <li><a class="reference internal" href="#checking-backup-consistency">Checking backup consistency</a></li> <li><a class="reference internal" href="#restoring-filesystem-backups">Restoring Filesystem Backups</a></li> <li><a class="reference internal" href="#restoring-bazaar-based-backups">Restoring Bazaar-based Backups</a></li> </ul> </li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="security.html" title="previous chapter">Security</a></p> <h4>Next topic</h4> <p class="topless"><a href="upgrade.html" title="next chapter">Upgrades</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/admin-guide/backup.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="upgrade.html" title="Upgrades" >next</a></li> <li class="right" > <a href="security.html" title="Security" >previous</a> |</li> <li><a href="http://bazaar.canonical.com/"> <img src="../_static/bzr icon 16.png" /> Home</a> | </li> <a href="http://doc.bazaar.canonical.com/en/">Documentation</a> | </li> <li><a href="../index.html">Table of Contents (2.6.0)</a> »</li> <li><a href="index.html" >Bazaar System Administrator’s Guide</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2011 Canonical Ltd. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </div> </body> </html>