title: create mongodb backup and upload to amazon s3
body: <p>I was trying to create MongoDB backup and upload it to amazon s3. This is my script.</p>
  
  <pre><code>#!/bin/bash  
  #Force file syncronization and lock writes
  
  mongo admin --eval "printjson(db.fsyncLock())"
  
  MONGODUMP_PATH="/home/ubuntu/backup/mongodb"
  MONGO_HOST="122.248.238.32"
  MONGO_PORT="27017"
  MONGO_DATABASE="eb"
  
  TIMESTAMP=`date +%F-%H%M`
  S3_BUCKET_NAME="MongodbBackup"
  S3_BUCKET_PATH="mongodb-backups"
  
  
  # Create backup
  $MONGODUMP_PATH -h $MONGO_HOST:$MONGO_PORT -d $MONGO_DATABASE
  
  # Add timestamp to backup
  mv dump mongodb-$HOSTNAME-$TIMESTAMP
  tar cf mongodb-$HOSTNAME-$TIMESTAMP.tar mongodb-$HOSTNAME-$TIMESTAMP
  
  # Upload to S3
  s3cmd put mongodb-$HOSTNAME-$TIMESTAMP.tar s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/mongodb-$HOSTNAME-$TIMESTAMP.tar
  
  
  #Unlock databases writes
  mongo admin --eval "printjson(db.fsyncUnlock())"
  </code></pre>
  
  <p>When I run this script, I am getting a response like this</p>
  
  <pre><code>MongoDB shell version: 2.4.6
  connecting to: admin
  {
      "info" : "now locked against writes, use db.fsyncUnlock() to unlock",
      "seeAlso" : "http://dochub.mongodb.org/core/fsynccommand",
      "ok" : 1
  }
  mv: cannot stat `dump': No such file or directory
  tar: mongodb-ip-10-145-167-183-2014-06-02-1055: Cannot stat: No such file or directory
  tar: Exiting with failure status due to previous errors
  WARNING: Module python-magic is not available. Guessing MIME types based on file extensions.
  mongodb-ip-10-145-167-183-2014-06-02-1055.tar -&gt; s3://MongodbBackup/mongodb-backups/mongodb-ip-10-145-167-183-2014-06-02-1055.tar  [1 of 1]
   10240 of 10240   100% in    1s     9.55 kB/s  done
  MongoDB shell version: 2.4.6
  connecting to: admin
  { "ok" : 1, "info" : "unlock completed" }
  </code></pre>
  
  <p>How can i create backup and upload to s3 properly?</p>