===========================================================
Anaconda repository backup and restore procedure (AER 2.32)
===========================================================

.. raw:: html

    <div class="section" id="preconditions">
    <h2>Preconditions<a class="headerlink" href="#preconditions" title="Permalink to this headline">¶</a></h2>
    <p>The following guide shows how to backup and restore an instance that uses local file system storage. For an instance that uses Amazon S3 or any other storage provider, please consult their specific documentation on backup and restore procedures.</p>
    <p>We also assume:</p>
    <ul class="simple">
    <li>The instance is installed in <code class="docutils literal"><span class="pre">/home/anaconda-server/repo</span></code> as suggested by the installation guide.</li>
    <li>The instance is owned by the <code class="docutils literal"><span class="pre">anaconda-server</span></code> user.</li>
    <li>The storage directory is <code class="docutils literal"><span class="pre">/opt/anaconda-server/package-storage</span></code>.</li>
    </ul>
    <p>If your instance has a different installation directory, owner, or storage directory, modify these instructions accordingly.</p>
    <p>Run all shell commands while logged in as the <code class="docutils literal"><span class="pre">anaconda-server</span></code> user. Using <code class="docutils literal"><span class="pre">sudo</span></code> privileges, log in as the <code class="docutils literal"><span class="pre">anaconda-server</span></code> user with this command:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">sudo</span> <span class="n">su</span> <span class="o">-</span> <span class="n">anaconda</span><span class="o">-</span><span class="n">server</span>
    </pre></div>
    </div>
    <p>Execute all commands in the working directory <code class="docutils literal"><span class="pre">/home/anaconda-server</span></code>:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>$ pwd
    /home/anaconda-server
    </pre></div>
    </div>
    </div>
    <div class="section" id="backup">
    <h2>Backup<a class="headerlink" href="#backup" title="Permalink to this headline">¶</a></h2>
    <p>Before starting the backup process, shut the service down using <code class="docutils literal"><span class="pre">supervisorctl</span></code>:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>$ supervisorctl stop all
    binstar-server: stopped
    $ supervisorctl status
    binstar-server                   STOPPED    Jul  6 05:05 PM
    </pre></div>
    </div>
    <p>Make a <code class="docutils literal"><span class="pre">$VERSION</span></code> environment variable and set it to the version of the currently installed Anaconda Repository:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>$ VERSION=`conda list binstar-server --json | python -c &#39;import sys, json; print json.load(sys.stdin)[0][&quot;version&quot;]&#39;`
    $ echo $VERSION
    2.32.6
    </pre></div>
    </div>
    <p>This version string will be used in all backup file names.</p>
    <p>It&#8217;s also useful to add a timestamp to the files, so generate one now:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>$ TIMESTAMP=`date +%Y-%m-%d`
    $ echo $TIMESTAMP
    2017-09-06
    </pre></div>
    </div>
    <div class="section" id="code-binaries">
    <h3>Code/Binaries<a class="headerlink" href="#code-binaries" title="Permalink to this headline">¶</a></h3>
    <p>Generate a tarfile archive with the installed code, binaries and any dependencies:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>$ tar -cpsf anaconda-server-repo-$VERSION-$TIMESTAMP.tar --exclude var/run -C /home/anaconda-server repo/
    $ sha1sum anaconda-server-repo-$VERSION-$TIMESTAMP.tar &gt; anaconda-server-repo-$VERSION-$TIMESTAMP.tar.sha1
    </pre></div>
    </div>
    <p>Notice that this also generated a SHA1 checksum. It will be verified when restoring the archive.</p>
    </div>
    <div class="section" id="configuration">
    <h3>Configuration<a class="headerlink" href="#configuration" title="Permalink to this headline">¶</a></h3>
    <p>This step is only necessary if you stored Anaconda Repository&#8217;s configuration in a custom location outside of the instance installation folder (usually <code class="docutils literal"><span class="pre">/home/anaconda-server/etc/</span></code>). We&#8217;ll assume that the configuration is stored in <code class="docutils literal"><span class="pre">/etc/anaconda-server</span></code>. Generate a tarfile with its SHA1 checksum:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>$ tar -cpsf anaconda-server-etc-$VERSION-$TIMESTAMP.tar /etc/anaconda-server
    $ sha1sum anaconda-server-etc-$VERSION-$TIMESTAMP.tar &gt; anaconda-server-etc-$VERSION-$TIMESTAMP.tar.sha1
    </pre></div>
    </div>
    </div>
    <div class="section" id="storage">
    <h3>Storage<a class="headerlink" href="#storage" title="Permalink to this headline">¶</a></h3>
    <p>As before, create a tarfile archive and its checksum with the contents of the package storage location:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>$ tar -cpsf anaconda-server-package-storage-$VERSION-$TIMESTAMP.tar -C /opt/anaconda-server/ package-storage
    $ sha1sum anaconda-server-package-storage-$VERSION-$TIMESTAMP.tar &gt; anaconda-server-package-storage-$VERSION-$TIMESTAMP.tar.sha1
    </pre></div>
    </div>
    </div>
    <div class="section" id="database">
    <h3>Database<a class="headerlink" href="#database" title="Permalink to this headline">¶</a></h3>
    <p>Generate a dump of Anaconda Repository&#8217;s MongoDB database. We recommend you follow MongoDB&#8217;s guidelines for <a class="reference external" href="https://docs.mongodb.com/manual/core/backups/">backup and restore</a>. This guide only shows how to do it using <a class="reference external" href="https://docs.mongodb.com/manual/tutorial/backup-and-restore-tools/">MongoDB tools</a>:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>$ mongodump --host=127.0.0.1 --port=27017 --archive=anaconda-server-mongodb-$VERSION-$TIMESTAMP.archive
    $ sha1sum anaconda-server-mongodb-$VERSION-$TIMESTAMP.archive &gt; anaconda-server-mongodb-$VERSION-$TIMESTAMP.archive.sha1
    </pre></div>
    </div>
    </div>
    <div class="section" id="bashrc">
    <h3>.bashrc<a class="headerlink" href="#bashrc" title="Permalink to this headline">¶</a></h3>
    <p>If you chose to let the Anaconda Repository installer update the <code class="docutils literal"><span class="pre">.bashrc</span></code> file of the user <code class="docutils literal"><span class="pre">anaconda-server</span></code>, you&#8217;ll also need to back it up:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>$ cp /home/anaconda-server/.bashrc anaconda-server-bashrc-$VERSION-$TIMESTAMP.sh
    $ sha1sum anaconda-server-bashrc-$VERSION-$TIMESTAMP.sh &gt; anaconda-server-bashrc-$VERSION-$TIMESTAMP.sh.sha1
    </pre></div>
    </div>
    </div>
    </div>
    <div class="section" id="restore">
    <h2>Restore<a class="headerlink" href="#restore" title="Permalink to this headline">¶</a></h2>
    <div class="section" id="id1">
    <h3>Preconditions<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
    <p>Before starting to restore Anaconda Repository, make sure that the environment meets the requirements listed in the <a class="reference internal" href="install.html"><span class="doc">Installation Guide</span></a> for Anaconda Repository. You will need:</p>
    <ul class="simple">
    <li>MongoDB (any supported version) installed</li>
    <li>A user account (usually <code class="docutils literal"><span class="pre">anaconda-server</span></code>)</li>
    <li>If you&#8217;re using a local filesystem as storage backend, you&#8217;ll need a storage directory (usually <code class="docutils literal"><span class="pre">/opt/anaconda-server/package-storage</span></code>) owned by the Anaconda Repository user account.</li>
    </ul>
    <p>Run all shell commands while logged in as the <code class="docutils literal"><span class="pre">anaconda-server</span></code> user, as you did when backing up Anaconda Repository. Using <code class="docutils literal"><span class="pre">sudo</span></code> privileges, log in as the <code class="docutils literal"><span class="pre">anaconda-server</span></code> user with this command:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">sudo</span> <span class="n">su</span> <span class="o">-</span> <span class="n">anaconda</span><span class="o">-</span><span class="n">server</span>
    </pre></div>
    </div>
    <p>Execute all commands in the working directory <code class="docutils literal"><span class="pre">/home/anaconda-server</span></code>.</p>
    </div>
    <div class="section" id="verify-checksums">
    <h3>Verify checksums<a class="headerlink" href="#verify-checksums" title="Permalink to this headline">¶</a></h3>
    <p>Verify the integrity of the backup files:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>$ sha1sum --check *.sha1
    anaconda-server-bashrc-2.32.6-2017-09-06.sh: OK
    anaconda-server-mongodb-2.32.6-2017-09-06.archive: OK
    anaconda-server-package-storage-2.32.6-2017-09-06.tar: OK
    anaconda-server-repo-2.32.6-2017-09-06.tar: OK
    </pre></div>
    </div>
    </div>
    <div class="section" id="id2">
    <h3>.bashrc<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
    <p>If you backed up the <code class="docutils literal"><span class="pre">.bashrc</span></code> file of the user <code class="docutils literal"><span class="pre">anaconda-server</span></code>, restore it:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>cp anaconda-server-bashrc-$VERSION-$TIMESTAMP.sh /home/anaconda-server/.bashrc
    </pre></div>
    </div>
    <p>You&#8217;ll need to login as <code class="docutils literal"><span class="pre">anaconda-server</span></code> once again for the changes to take effect.</p>
    </div>
    <div class="section" id="id3">
    <h3>Database<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h3>
    <p>If you followed the first steps of the Anaconda Repository <a class="reference internal" href="install.html"><span class="doc">Installation Guide</span></a>, MongoDB is up and running and you can use <code class="docutils literal"><span class="pre">mongorestore</span></code> to restore the database archive:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>mongorestore --host=127.0.0.1 --port=27017 --db=binstar --archive=anaconda-server-mongodb-$VERSION-$TIMESTAMP.archive
    </pre></div>
    </div>
    </div>
    <div class="section" id="id4">
    <h3>Storage<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h3>
    <p>Assuming that the storage directory is <code class="docutils literal"><span class="pre">/opt/anaconda-server/package-storage</span></code>, restore it with:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>tar -xpsf anaconda-server-package-storage-$VERSION-$TIMESTAMP.tar -C /opt/anaconda-server/
    </pre></div>
    </div>
    </div>
    <div class="section" id="id5">
    <h3>Code/Binaries<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h3>
    <p>Restore the code and binaries:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>tar -xpsf anaconda-server-repo-$VERSION-$TIMESTAMP.tar -C /home/anaconda-server
    </pre></div>
    </div>
    <p>Restore the <code class="docutils literal"><span class="pre">supervisord</span></code> configuration:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">repo</span><span class="o">/</span><span class="nb">bin</span><span class="o">/</span><span class="n">anaconda</span><span class="o">-</span><span class="n">server</span><span class="o">-</span><span class="n">install</span><span class="o">-</span><span class="n">supervisord</span><span class="o">-</span><span class="n">config</span><span class="o">.</span><span class="n">sh</span>
    </pre></div>
    </div>
    <p>The server should now be up and running. Check the status with <code class="docutils literal"><span class="pre">supervisorctl</span></code>:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span>$ repo/bin/supervisorctl status
    binstar-server                   RUNNING    pid 8446, uptime 0:03:18
    </pre></div>
    </div>
    </div>
    </div>
