简体   繁体   English

如何在 pg_dump 后使用 pg_restore 和 github 操作清理数据库

[英]how to clean database after pg_dump with pg_restore with github actions

I would make the backup for database A, and put the backup to database B, before putting the backup into B, I would clean B with workflow in GitHub actions I try this.我将为数据库 A 进行备份,并将备份放入数据库 B,在将备份放入 B 之前,我将使用 GitHub 操作中的工作流清理 B 我试试这个。 but GitHub tells me that pg_restore doesn't have options how can I clean my database B before putting my backup into 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 actions saying: Github 动作说:

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

So the clean doesn't work?所以清洁不起作用? how can I clean my DB?我怎样才能清理我的数据库?

I found a solution to my problem:我找到了解决问题的方法:

     - 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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM