bin bash MONGODUMP_PATH usr bin mongodump MONGO_HOST localhost HOSTNAM

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
MONGODUMP_PATH="/usr/bin/mongodump"
MONGO_HOST="localhost"
HOSTNAME="debian"
TIMESTAMP=`date +%F-%H%M`
S3_BUCKET_NAME="project-backups"
S3_BUCKET_PATH="mongodb-backups"
# Create backup
$MONGODUMP_PATH --host $MONGO_HOST
# Add timestamp to backup
mv dump mongodb-$HOSTNAME-$TIMESTAMP
tar cfz mongodb-$HOSTNAME-$TIMESTAMP.tgz mongodb-$HOSTNAME-$TIMESTAMP
#rm -rf mongodb-$HOSTNAME-$TIMESTAMP
# Upload to S3
s3cmd put mongodb-$HOSTNAME-$TIMESTAMP.tgz s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/mongodb-$HOSTNAME-$TIMESTAMP.tgz
unlink mongodb-$HOSTNAME-$TIMESTAMP.tgz