gpt4 book ai didi

heroku - 将 heroku pg 备份存储在自己的 S3 存储桶上

转载 作者:行者123 更新时间:2023-12-04 11:32:14 25 4
gpt4 key购买 nike

Heroku 为您的 PG 数据库提供自动和计划备份。
https://devcenter.heroku.com/articles/heroku-postgres-data-safety-and-continuous-protection

GBackups will launch a dedicated dyno to take a dump of your database and upload it to S3



简单的问题:是否可以将预定的 PG 备份上传到自己的 S3 Bucket?只需控制备份文件,不受存储空间的限制。如果可能的话,研究这个主题并没有为我提供答案。

最佳答案

您可以使用 Heroku 调度程序和 bash 脚本来完成。

# Set the script to fail fast if there
# is an error or a missing variable

set -eu
set -o pipefail

#!/bin/sh

# Download the latest backup from
# Heroku and gzip it

heroku pg:backups:download --output=/tmp/pg_backup.dump --app $APP_NAME
gzip /tmp/pg_backup.dump

# Encrypt the gzipped backup file
# using GPG passphrase

gpg --yes --batch --passphrase=$PG_BACKUP_PASSWORD -c /tmp/pg_backup.dump.gz

# Remove the plaintext backup file

rm /tmp/pg_backup.dump.gz

# Generate backup filename based
# on the current date

BACKUP_FILE_NAME="heroku-backup-$(date '+%Y-%m-%d_%H.%M').gpg"

# Upload the file to S3 using
# AWS CLI

aws s3 cp /tmp/pg_backup.dump.gz.gpg "s3://${S3_BUCKET_NAME}/${BACKUP_FILE_NAME}"

# Remove the encrypted backup file

rm /tmp/pg_backup.dump.gz.gpg

您可以查看 this tutorial有关详细的分步说明。

关于heroku - 将 heroku pg 备份存储在自己的 S3 存储桶上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36287630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com