- Open AWS S3 https://console.aws.amazon.com/s3/home
- Create a new S3 bucket for backup
Example name: ans-backup
- Open AWS IAM policies https://console.aws.amazon.com/iam/home#/policies
- Create a new IAM policy for backup bucket
- Select
Policy Generator
Effect: Allow
AWS Service: Amazon S3
Actions: All Actions (*)
ARN: arn:aws:s3:::ans-backup/* (use bucket name from previous step)
- Press
Add Statement
- Press
Next Step
- Change
Policy Name
- Change resource like below
"Resource": [
"arn:aws:s3:::ans-backup/*",
"arn:aws:s3:::ans-backup"
]
- Press
Create Policy
- Open AWS IAM https://console.aws.amazon.com/iam/home#/users
- Create new user
- Save new credentials
- Attach above policy to the user
# for example:
s3_backup_bucket: ans-backup
s3_backup_aws_access_key_id: YOURID
s3_backup_aws_secret_access_key: YOURKEY
s3_backup_region: us-west-1
s3_backup_script: /root/s3-db-backup.sh
s3_backup_cron_minutes: "15"
s3_backup_cron_hours: "6,18"
add 'awscli' to 'setup_common_required_packages'
setup_common_required_packages:
- awscli
tag:
update_packages
#for staging
ansible-playbook -i inventories/staging init.yml -t update_packages --ask-vault-pass
#for production
ansible-playbook -i inventories/production init.yml -t update_packages --ask-vault-pass
tag:
prep_s3_backup
env:
db_backup=true
#for staging
ansible-playbook -i inventories/staging backup.yml -t prep_s3_backup -e 'db_backup=true' --ask-vault-pass
#for production
ansible-playbook -i inventories/production backup.yml -t prep_s3_backup -e 'db_backup=true' --ask-vault-pass
tag:
run_s3_backup
env:
db_restore=true
#for staging
ansible-playbook -i inventories/staging backup.yml -t run_s3_backup -e 'db_backup=true' --ask-vault-pass
#for production
ansible-playbook -i inventories/production backup.yml -t run_s3_backup -e 'db_backup=true' --ask-vault-pass
- open https://console.aws.amazon.com/s3/home
- select your backup bucket
- download archive locally
tag:
upload_backup_mongo
restore_mongo
env:
db_restore=true
init_setup=true
upload_backup_path=~/Downloads/ps.gz
(set your path to archive from previous step)
#for staging
ansible-playbook -i inventories/staging main.yml -t upload_backup_mongo,restore_mongo -e 'db_restore=true init_setup=true upload_backup_path=~/Downloads/ps.gz' --ask-vault-pass
#for production
ansible-playbook -i inventories/production main.yml -t upload_backup_mongo,restore_mongo -e 'db_restore=true init_setup=true upload_backup_path=~/Downloads/ps.gz' --ask-vault-pass