SHARE
TWEET

Untitled

a guest May 22nd, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. echo "***** Validating arguments *****"
  4.  
  5. if [ $# -eq 3 ]
  6.     then
  7.         echo "Number of arguments is valid."
  8.     else
  9.           echo "Invalid number of arguments provided!"
  10.                 echo "Expected: 3"
  11.                 echo "SERVICE"
  12.                 echo "DB_NAME"
  13.                 echo "BACKUP_PATH"
  14.           echo "Provided: $#"
  15.           exit 1
  16. fi
  17.  
  18.  
  19. SERVICE=$1
  20. DB_NAME=$2
  21. BACKUP_PATH=$3
  22.  
  23. echo "********* Getting container ID *********"
  24.  
  25. CONTAINER_ID=$(for f in $(docker service ps -q --filter desired-state=running $SERVICE); do docker inspect --format '{{.Status.ContainerStatus.ContainerID}}' $f; done)
  26.  
  27. echo "Container id is: $CONTAINER_ID"
  28.  
  29. DATE_AND_TIME=$(date '+%d-%m-%Y-%H:%M:%S')
  30.  
  31. echo "********* Executing mongo dump *********"
  32.  
  33. docker exec -it $CONTAINER_ID mongodump -d $DB_NAME
  34.  
  35.  
  36. echo "******** Backing up data to $BACKUP_PATH/$DB_NAME/$DATE_AND_TIME ********"
  37.  
  38. OUTDIR=$BACKUP_PATH/$DB_NAME/$DATE_AND_TIME
  39.  
  40. mkdir -p $OUTDIR
  41.  
  42. docker cp $CONTAINER_ID:dump/$DB_NAME/. $OUTDIR
  43.  
  44. echo "******** Success, backup completed. *********"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top