baniol
6/10/2014 - 6:21 PM

mongodb dump & dropbox upload, backup

mongodb dump & dropbox upload, backup

#!/usr/bin/env bash

#Get current date
NOW="$(date +'%d-%m-%Y_%H-%M')"

# Settings:

# Path to a temporary directory
DIR=/root/mongodb_dump/

# Path to a target dropbox directory
# Remove after article - create first a target file in dropboxs
TARGET_DIR=/mongodb_backups

# Path do dropbox_uploader.sh file
UPLOADER_SCRIPT=/root/downloads/dropbox_uploader.sh

# Name of the database
DB_NAME=clippings

function mongodb_dump
{
  # Name of the compressed file
  FILE="${DIR}${DB_NAME}_${NOW}.tar.gz"

  echo $FILE

  # Dump the database
  mongodump -d $DB_NAME -o $DIR

  # Compress~
  tar -zcvf $FILE $DIR$DB_NAME

  # Remove the temporary database dump directory
  rm -fr $DB_NAME

  # Upload the file
  $UPLOADER_SCRIPT upload $FILE $TARGET_DIR

  # Remove the file
  rm $FILE
}

mongodb_dump