涵虚 Back-end Dev Engineer

备份Docker中的Gitlab

2016-08-15

  • content {toc}

事先不知道使用了外部数据库,所以运行命令的结果,如下:

sudo docker run --name e78ebe5ca822 -it --rm sameersbn/gitlab:8.6.2 app:rake gitlab:backup:create --env 'DB_ADAPTER=mysql2' --env 'DB_HOST=192.168.1.129' --env 'DB_NAME=gitlabhq_production' --env 'DB_USER=gitlab' --env 'DB_PASS=root'
Initializing logdir...
Initializing datadir...
Generating OpenSSH host keys... RSA1 RSA DSA ECDSA ED25519 
Installing configuration templates...
Configuring gitlab...
Configuring gitlab::database
ERROR: 
  Please configure the database connection.
  Refer http://git.io/wkYhyA for more information.
  Cannot continue without a database. Aborting...

从上面的输出结果你也可以看到,我们要连接数据库才能继续后面的操作。

因为使用的外部Mysql数据库,所以要先连接数据库,这样就不会报错。这样备份的就是gitlab的tar文件,而不是整个docker镜像文件。

sudo docker run --name e78ebe5ca822 --env 'DB_ADAPTER=mysql2' --env 'DB_HOST=192.168.1.129' --env 'DB_NAME=gitlabhq_production' --env 'DB_USER=gitlab' --env 'DB_PASS=root'  --env 'GITLAB_BACKUP_DIR=./' -it --rm sameersbn/gitlab:8.6.2 app:rake gitlab:backup:create  

在Debian上还原,这个还原操作直接用命令 sudo docker commit -p 2f9fd7ce6466 gitlab_bak 备份了docker镜像,而后在另外Debian上 sudo docker load -i ./gitlab_8.6.2_bak.tar 载入镜像文件。

执行以上操作,然后运行下面命令以便运行镜像:

sudo docker run -m=2048M --name gitlab_bak -d \
                      --link gitlab-redis:latest \
                      --publish 10022:22 --publish 10080:80 \
                      --env 'GITLAB_PORT=10080' --env 'GITLAB_SSH_PORT=10022' \
                      --env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \
                      --env 'DB_ADAPTER=mysql2' --env 'DB_HOST=192.168.1.129' \
                      --env 'DB_NAME=gitlabhq_production' \
                      --env 'DB_USER=gitlab' --env 'DB_PASS=root' \
                      --volume /srv/docker/gitlab/gitlab:/home/git/data \
                      gitlab_bak

但是这样还会遇到问题,其报错输出如下:

WARNING: Your kernel does not support memory limit capabilities. Limitation discarded.
WARNING: Your kernel does not support memory swappiness capabilities, memory swappiness discarded.
316b26e54b77578140e4e9c156a2c9d2597c1081dc6d67e66fd8041292d1e7a3

Comments