データベースのバックアップをする #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Backup PostgreSQL Database | |
on: | |
schedule: | |
- cron: "0 19 * * *" # 毎日午前2時に実行 | |
pull_request: # PR 作成や更新時にトリガー | |
branches: | |
- main | |
push: # 通常の push 時にもトリガー | |
branches: | |
- main | |
jobs: | |
backup: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install PostgreSQL Client | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y postgresql-client-15 | |
- name: Backup database | |
run: | | |
pg_dump -h ${{ secrets.PG_HOST }} \ | |
-p ${{ secrets.PG_PORT }} \ | |
-U ${{ secrets.PG_USER }} \ | |
-d ${{ secrets.PG_DB }} \ | |
--file=backup.sql | |
env: | |
PGPASSWORD: ${{ secrets.PG_PASSWORD }} | |
- name: Upload backup to GitHub | |
uses: actions/upload-artifact@v3 | |
with: | |
name: pg-dump-backup | |
path: backup.sql |