Heroku Advent Calendar 2016 Day 6 article. I've been writing Heroku's Advent Calendar for about three years in a row, no matter what.
I was inspired by this article by Crowdworks.
I created a Docker container that can execute the following shell commands, which I did in the above article Adding a preview environment that can synchronize data with production.
- Copy Heroku Postgres from the Production environment to the Staging environment
- Mask personal information from the copied DB
- Synchronize the Puroduction environment bucket in AWS S3 to the Staging environment bucket
I'm deploying this Docker container to Heroku.
As you can see, Heroku has a mechanism to deploy Docker containers, which is not well known, but it is actually made before you know it.
In order to run the backup command in heroku or the CLI in AWS, as in this case
Rather than making an existing build pack (or rather, a build pack that could do something about it, but I haven't looked it up)
I think it's more convenient to create Docker container because it's easier to check the operation on the development machine.
In the case of Docker container, if you can deploy Docker container other than Heroku, you can build it in any cloud environment, even in a suitable internal server, I think it is a good point.
Obtain the AWS and Heroku API keys in advance and make a note of them
The URLs for each method are as follows
firstname.lastname@example.org:konyu/heroku-aws-backup.git cd heroku-aws-backup docker build --rm -t heroku-aws-backup .
Start with AWS and Heroku environment variables in --env
docker run -it --rm --env AWS_ACCESS_KEY_ID=xxxxxxx\fnDroid --env AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx} --env AWS_DEFAULT_REGION=ap-northeast-1 --env HEROKU_API_KEY=xxxxxxxxxxxxxxxxxxxxx heroku-aws-backup bash
If you're using a cloned Github repository as I write here, you can use
There is a sample file for backup in sh/backup.sh, so you can rewrite it to suit your environment.
It would be good to make sh/backup.sh and rewrite the shell file appropriately when you write it in the From of Dockerfile and use it.
# sample backup shell # echo "start daily buckup!!!" # echo "== stopping worker ==" # heroku ps:scale worker=0 -a APP_BE_BAKED_UP # echo "== copying database to preview from production ==" # heroku pg:copy ORIGINAL_DB_NAME DB_TO_BE_COPIED --confirm APP_BE_BAKED_UP -a APP_BE_BAKED_UP # echo "== clearing jobs ==" # heroku run rake jobs:clear -a APP_BE_BAKED_UP # echo "== copying s3 bucket to staging from production ==" # aws s3 sync --delete --acl public-read s3://ORIGINAL_BUCKET s3://BUCKET_TO_BE_COPIED # echo "== starting worker ==" # heroku ps:scale worker=1 -a APP_BE_BAKED_UP
If you don't have Heroku's CLI command installed, you should be able to use the OS in the following URL
heroku plugins:install heroku-container-registry
Move to this repository directory
heroku login > enter your id and password
heroku create APP_NAME_YOU_WANT
Added git remote to be able to deploy to heroku
heroku git:remote -a APP_NAME_YOU_WANT
heroku container:push web
Setting environment variables heroku config:set AWS_ACCESS_KEY_ID=xxxxxxx AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxx AWS_DEFAULT_REGION=ap-northeast-1 HEROKU_API_KEY=xxxxx -app APP_NAME_YOU_WANT
heroku addons:create scheduler:standard -app APP_NAME_YOU_WANT
The shell to run should be written with the full path.
Note that it doesn't work well if you write the path relative to your home directory when you start with
heroku run bash -a APP_NAME.