将 OpenProject 数据库从软件包安装迁移到 Docker 容器

将 OpenProject 数据库从软件包安装迁移到 Docker 容器

我见过一些人将 OpenProject 从容器迁移到软件包安装,但反之则不然。OpenProject 的迁移说明假设您正在从容器迁移到容器或从软件包迁移到软件包安装。

在包安装上导出 postgres 数据库很简单:

$  sudo openproject run backup

...剩下:

attachments-<date>.tar.gz
conf-20200226142943.tar.gz
postgresql-dump-20200226142943.pgdump

在 /var/db/openproject/backup 中

但之后呢?本页上的说明 (https://docs.openproject.org/installation-and-operations/operation/restoring/#restoring-the-database) 仅解释如何从容器导入到容器,而不是从包安装。

有人做过这个吗?看起来应该很容易,但我就是搞不懂。

答案1

以下是我如何做到的一些简要说明:

  • 比较了 PostgreSQL Docker 容器与实时文件,并将一些文件从 docker 移动到 OP 设置,例如pg_hba.conf&postgresql.conf
  • 没有导入/导出数据库,但移动了实际文件,然后将 PSQL/OP 容器指向这些文件
  • 我使用另一个httpd容器来代理 SSL 前端,并将 OP 容器配置保留为默认配置

这是一些通用代码!

version: '3.2'

services:
  openproject:
    image: openproject/community:${OP_VER}
    container_name: openproject
    hostname: openproject
    networks:
      - openprojectnet
    depends_on:
      - opdb
#      - ophttpd
    volumes:
      - type: bind
        source: /opt/op/assets/
        target: /var/openproject/assets

    ports:
      - '8080:8080'

    environment:
      - 'TZ=${TZ}'
      - 'SECRET_KEY_BASE=${SECRET_KEY_BASE}'
      - 'EMAIL_DELIVERY_METHOD=${EMAIL_DELIVERY_METHOD}'
      - 'SMTP_ADDRESS=${SMTP_ADDRESS}'
      - 'SMTP_PORT=${SMTP_PORT}'
      - 'SMTP_DOMAIN=${SMTP_DOMAIN}'
      - 'SMTP_AUTHENTICATION=${SMTP_AUTHENTICATION}'
      - 'SMTP_ENABLE_STARTTLS_AUTO=${SMTP_ENABLE_STARTTLS_AUTO}'
      - 'SMTP_USER_NAME=${SMTP_USER_NAME}'
      - 'SMTP_PASSWORD=${SMTP_PASSWORD}'
      - 'DATABASE_URL=${POSTGRES_DATABASE_URL}' #Forced 'External DB Server
      - 'SERVER_HOSTNAME=${SERVER_HOSTNAME}'
#      - 'OPENPROJECT_EDITION=${OPENPROJECT_EDITION}' = Community/Std etc

  opdb:
    container_name: openproject_sql
    hostname: openprojectsql
    networks:
      - openprojectnet
    image: postgres:${PGSQL_VER}
    ports:
      - '5432:5432'
    volumes:
      - type: bind
        source: /opt/op/psql/
        target: /var/lib/postgresql/data

    environment:
      - 'POSTGRES_USER=${DB_USER}'
      - 'POSTGRES_PASSWORD=${DB_PWD}'
      - 'POSTGRES_DB=${DB_NAME}'
      - 'POSTGRES_ENCODING=UTF8'
      - 'POSTGRES_COLLATE=C'
      - 'POSTGRES_COLLATE_TYPE=C'


  ophttpd:
    container_name: httpd
    image: httpd
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - type: volume #Even tho no html files are served, must define html volume as its required in base httpd image
        source: html
        target: /usr/local/apache2/htdocs
      - type: bind   # Comment this out, run container, and pull files from dir to host, then uncomment
        source: /opt/op/httpd/ # docker cp httpd:/usr/local/apache2/conf/ /opt/httpd/
        target: /usr/local/apache2/conf/

    environment:
      - 'TZ=${TZ}'

networks:
  openprojectnet:
    driver: bridge

#None of these volumes are used, just required by base image, all data is using BIND
volumes:
  html:

#Assets
#Run on Old_PROD
tar -zcvf /root/op_migrate/op_vardb.tgz /var/db/openproject/
scp /root/op_migrate/op_vardb.tgz [email protected]:/root/op_migrate/op_vardb.tgz

#SQL
#Run on Old_PROD
tar -zcvf /root/op_migrate/op_psql.tgz /var/lib/postgresql/13/main/
scp /root/op_migrate/op_psql.tgz [email protected]:/root/op_migrate/op_psql.tgz

#Assets
#Run on New_Prod
cd /root/op_migrate/
rm /opt/op/assets/* -R

tar -zxvf op_vardb.tgz
cp var/db/openproject/* /opt/op/assets/ -R
rm var -R

#SQL
#Run on New_Prod
cd /root/op_migrate/
rm /opt/op/psql/* -R

tar -zxvf op_psql.tgz
cp var/lib/postgresql/13/main/* /opt/op/psql/ -R
rm var -R
rm /opt/op/psql/*.pid
cp /opt/op/setup/sql/pg_hba.conf /opt/op/psql/
cp /opt/op/setup/sql/postgresql.conf /opt/op/psql/
cp /opt/op/setup/sql/.pgpass /root/.pgpass

相关内容