Anaconda 企业 4 仓库备份和恢复程序#

本指南适用于备份和恢复使用本地文件系统存储的 Anaconda 企业 4 仓库实例。如果您的实例使用 Amazon S3 或任何其他存储提供商,请查阅他们关于备份和恢复程序的特定文档。

开始之前#

这些说明适用于以下仓库:

  • 安装在目录 /home/anaconda-server/repo 中,如安装指南建议的那样。

  • anaconda-server 用户拥有。

  • 使用存储目录 /opt/anaconda-server/package-storage

  • 将配置文件存储在 /etc/anaconda-server 中。

如果您的实例的任何这些项目不同,请相应地修改这些说明。

  • 除非另有说明,否则以 anaconda-server 用户身份登录时运行所有 shell 命令。使用 sudo 权限,使用以下命令以 anaconda-server 用户身份登录

    sudo su - anaconda-server
    
  • 在工作目录 /home/anaconda-server 中执行所有命令

    $ pwd
    /home/anaconda-server
    

备份#

在开始备份过程之前,使用 supervisorctl 关闭服务

$ supervisorctl stop all
anaconda-server: stopped
$ supervisorctl status
anaconda-server                   STOPPED    Jul  6 05:05 PM

创建一个 $VERSION 环境变量,并将其设置为当前安装的 Anaconda 企业 4 仓库的版本

$ VERSION=`conda list anaconda-server --json | python -c 'import sys, json; print json.load(sys.stdin)[0]["version"]'`
$ echo $VERSION
2.33.27

此版本字符串将用于所有备份文件名。

在文件中添加时间戳也很有用,因此现在生成一个

$ TIMESTAMP=`date +%Y-%m-%d`
$ echo $TIMESTAMP
2018-07-30

代码/二进制文件#

生成包含已安装代码、二进制文件和任何依赖项的 tarfile 存档

$ tar -cpsf anaconda-server-repo-$VERSION-$TIMESTAMP.tar --exclude var/run -C /home/anaconda-server repo/
$ sha1sum anaconda-server-repo-$VERSION-$TIMESTAMP.tar > anaconda-server-repo-$VERSION-$TIMESTAMP.tar.sha1

请注意,这也生成了 SHA1 校验和。此校验和将用于在您恢复存档时进行验证。

配置#

仅当您将 Anaconda 企业 4 仓库的配置存储在实例安装文件夹(通常为 /home/anaconda-server/etc/)之外的自定义位置时,才需要执行此步骤。

以下命令显示了如果配置存储在 /etc/anaconda-server 中,如何生成 tarfile。

生成 tarfile 及其 SHA1 校验和

$ tar -cpsf anaconda-server-etc-$VERSION-$TIMESTAMP.tar /etc/anaconda-server
$ sha1sum anaconda-server-etc-$VERSION-$TIMESTAMP.tar > anaconda-server-etc-$VERSION-$TIMESTAMP.tar.sha1

存储#

与之前一样,使用包存储位置的内容创建 tarfile 存档及其校验和

$ tar -cpsf anaconda-server-package-storage-$VERSION-$TIMESTAMP.tar -C /opt/anaconda-server/ package-storage
$ sha1sum anaconda-server-package-storage-$VERSION-$TIMESTAMP.tar > anaconda-server-package-storage-$VERSION-$TIMESTAMP.tar.sha1

数据库#

生成 Anaconda 企业 4 仓库的 MongoDB 数据库的转储。Anaconda 建议您遵循 MongoDB 的 备份和恢复 指南。本指南使用 MongoDB 工具

$ mongodump --host=127.0.0.1 --port=27017 --archive=anaconda-server-mongodb-$VERSION-$TIMESTAMP.archive
$ sha1sum anaconda-server-mongodb-$VERSION-$TIMESTAMP.archive > anaconda-server-mongodb-$VERSION-$TIMESTAMP.archive.sha1

.bashrc#

如果您选择让 Anaconda 企业 4 仓库安装程序更新用户 anaconda-server.bashrc 文件,请备份它

$ cp /home/anaconda-server/.bashrc anaconda-server-bashrc-$VERSION-$TIMESTAMP.sh
$ sha1sum anaconda-server-bashrc-$VERSION-$TIMESTAMP.sh > anaconda-server-bashrc-$VERSION-$TIMESTAMP.sh.sha1

恢复#

开始之前#

  • 验证恢复环境是否满足 安装指南 中列出的 Anaconda 企业 4 仓库的要求。您将需要

    • 已安装 MongoDB(任何受支持的版本)

    • 用户帐户(通常为 anaconda-server

    • 存储目录(通常为 /opt/anaconda-server/package-storage),由 Anaconda 企业 4 仓库用户帐户拥有。仅当您使用本地文件系统作为存储后端时才需要此项。

  • 与备份 Anaconda 企业 4 仓库时一样,以 anaconda-server 用户身份登录时运行所有 shell 命令。使用 sudo 权限,使用以下命令以 anaconda-server 用户身份登录

    sudo su - anaconda-server
    
  • 在工作目录 /home/anaconda-server 中执行所有命令。

验证校验和#

验证备份文件的完整性

$ sha1sum --check *.sha1
anaconda-server-bashrc-2.33.27-2018-07-30.sh: OK
anaconda-server-mongodb-2.33.27-2018-07-30.archive: OK
anaconda-server-package-storage-2.33.27-2018-07-30.tar: OK
anaconda-server-repo-2.33.27-2018-07-30.tar: OK

.bashrc#

如果您备份了用户 anaconda-server.bashrc 文件,请恢复它

cp anaconda-server-bashrc-$VERSION-$TIMESTAMP.sh /home/anaconda-server/.bashrc

恢复此文件后,注销并以 anaconda-server 身份重新登录,以使更改生效。

数据库#

如果您遵循了 Anaconda 企业 4 仓库 安装指南,则 MongoDB 正在运行,您可以使用 mongorestore 来恢复数据库存档

mongorestore --host=127.0.0.1 --port=27017 --db=binstar --archive=anaconda-server-mongodb-$VERSION-$TIMESTAMP.archive

存储#

假设存储目录为 /opt/anaconda-server/package-storage,请使用以下命令恢复它

tar -xpsf anaconda-server-package-storage-$VERSION-$TIMESTAMP.tar -C /opt/anaconda-server/

代码/二进制文件#

恢复代码和二进制文件

tar -xpsf anaconda-server-repo-$VERSION-$TIMESTAMP.tar -C /home/anaconda-server

恢复 supervisord 配置

repo/bin/anaconda-server-install-supervisord-config.sh

服务器现在应该已启动并正在运行。使用 supervisorctl 检查状态

$ repo/bin/supervisorctl status
anaconda-server                   RUNNING    pid 8446, uptime 0:03:18