【问题标题】:how to clean database after pg_dump with pg_restore with github actions如何在 pg_dump 之后使用 pg_restore 和 github 操作清理数据库
【发布时间】:2022-08-04 23:04:26
【问题描述】:

我会为数据库 A 进行备份,并将备份放入数据库 B,在将备份放入 B 之前,我会在 GitHub 操作中使用工作流清理 B 我尝试这个。 但 GitHub 告诉我 pg_restore 没有选项 在将备份放入 B 之前,如何清理数据库 B?

      - name: Add hosts to /etc/hosts
        run: sudo echo \"nameserver ****************\" >> /etc/resolv.conf
      -   name: Install pg_dump
          run: sudo apt-get install postgresql-client -y
      - name: Postgres Dump Backup
        uses: tj-actions/pg-dump@v2.3
        with:
          database_url: \"postgres://USER:PWD@HOST:5432/DB_A\"
          path: \"backups/backup.sql\" 
          options: \"-O\" 
      - name: Postgres Backup Restore
        uses: tj-actions/pg-restore@v4.5
        with:
          database_url: \"postgres://USER:PWD@HOST:5432/DB_B\"
          backup_file: \"backups/backup.sql\"
          # clean options not working
          options: \"-c\"      

Github 行动说:

Warning: Unexpected input(s) \'options\', valid inputs are [\'database_url\', \'backup_file\']

所以清洁不起作用?我怎样才能清理我的数据库?

  • 请显示错误信息
  • @rethab,我刚刚编辑了我的帖子,我有一个警告说 ``` 警告:意外的输入 \'options\',有效输入是 [\'database_url\', \'backup file\'] ```
  • options 输入仅在 main 上可用,但尚未随标签一起发布。您可以询问维护者是否要发布新版本(我看到您已经opened an issue)或使用uses: tj-actions/pg-restore@main 之类的操作。
  • @rethab,我尝试使用 uses: tj-actions/pg-restore@main 但我有 /usr/lib/postgresql/12/bin/psql: unrecognized option \'--clean\' 错误
  • --clean 不是 psql 的有效选项:postgresql.org/docs/current/app-psql.html

标签: postgresql yaml github-actions pg-dump pg-restore


【解决方案1】:

我找到了解决问题的方法:

     - name: Postgres Dump Backup
        uses: tj-actions/pg-dump@v2.3
        with:
          database_url: "postgres://USER_NAME:PWDp@HOST:5432/DB_A"
          path: "backups/backup.sql" 
          options: "-O"
      - name: Delete  schema of DB destination
        run: psql -d "postgres://USER_NAME:PWDp@HOST:5432/DB_B" -c "DROP SCHEMA IF EXISTS schema_name CASCADE;"
      - name: Recreate schema of DB destination
        run: psql -d "postgres://USER_NAME:PWDp@HOST:5432/DB_B" -c "CREATE SCHEMA IF NOT EXISTS schema_name;"
      - name: Restore Backup into DB Destination
        uses: tj-actions/pg-restore@v4.5
        with:
          database_url: "postgres://USER_NAME:PWDp@HOST:5432/DB_B"
          backup_file: "backups/backup.sql"

【讨论】:

    猜你喜欢
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多