#!/bin/bash datetime=`date +%Y%m%d%H` mkdir -p ~/.aws echo -ne "[default]\naws_access_key_id = ${AWS_ACCESS_KEY}\naws_secret_access_key = ${AWS_SECRET_KEY}\n" > ~/.aws/credentials dbs=($DATABASES) for db in "${dbs[@]}" do mongodump --host ${HOST} --port ${PORT} --authenticationDatabase admin -u backup -p ${PASSWORD} --db $db --gzip --archive=${db}.tgz if (($?==0));then aws s3 cp ${db}.tgz s3://bfs-pkg-storage/mongodb/backup/${datetime}/ else echo "Backup to failed" exit 1 fi done