我想每天转储我可以存储在S3中的生产数据库。我已经创建了一个在本地工作正常的bash脚本,但是当在Heroku的postinstall上运行时,我收到以下错误消息:
./run-backup.sh: line 21: mysqldump: command not found
因为它试图运行以下行:
mysqldump -u $CLEARDB_USER_NAME -h $CLEARDB_SERVER_IP -p$CLEARDB_PASSWORD --databases $DATABASE | gzip -c > "/tmp/db-backups/$BACKUP_FILE_NAME.gz"
因此脚本运行正常,但Heroku无法运行它。我不知道从哪里开始?
以下是完整的脚本:
#!/bin/bash
echo "Beginning database backup"
#install aws-cli
curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -o awscli-bundle.zip
unzip awscli-bundle.zip
chmod +x ./awscli-bundle/install
./awscli-bundle/install -i /tmp/aws
# new backup file name
BACKUP_FILE_NAME="$(date +"%Y-%m-%d-%H-%M")-$APP-$DATABASE.sql"
# if directory '/tmp/db-backups' doesn't exist, create it
if [ ! -d "/tmp/db-backups" ]; then
mkdir -p /tmp/db-backups/
fi
# dump the current DB into /tmp/db-backups/<new-file-name>
mysqldump -u $CLEARDB_USER_NAME -h $CLEARDB_SERVER_IP -p$CLEARDB_PASSWORD --databases $DATABASE | gzip -c > "/tmp/db-backups/$BACKUP_FILE_NAME.gz"
# using the aws cli, copy the new backup to our s3 bucket
/tmp/aws/bin/aws s3 cp /tmp/db-backups/$BACKUP_FILE_NAME.gz s3://$S3_BUCKET_PATH/$DATABASE/$BACKUP_FILE_NAME.gz --region $AWS_DEFAULT_REGION
echo "backup $BACKUP_FILE_NAME.gz complete"