Last active
May 18, 2016 11:55
-
-
Save singhabhinav/a451bce58996ea6ad9fb41b6643b5f5f to your computer and use it in GitHub Desktop.
Take Ambari server backup and move to S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script will take backup of ambari server and move to S3 | |
# Make sure you have s3cmd installed and configured https://github.com/s3tools/s3cmd | |
# Customize it according to your need | |
#!/bin/bash | |
USERNAME=$1 | |
export PGPASSWORD=$2 | |
DB=ambari | |
DATE=`date` | |
WEEK_OF_YEAR=`date "+%V"` | |
YEAR=`date "+%Y"` | |
DATE=`echo "$DATE" | sed 's/ /_/g' | sed 's/:/./g'` | |
DUMPFILENAME=$DB.$DATE | |
DUMPPATH=. | |
sudo ambari-server stop | |
/usr/bin/pg_dump -U $USERNAME $DB > $DUMPPATH/$DUMPFILENAME.sql | |
sudo ambari-server start | |
gzip $DUMPPATH/$DUMPFILENAME.sql | |
S3SYNC=/usr/bin/s3cmd | |
S3BUCKET_NAME=YOUR_S3_BCUKET/$DB/$YEAR/$WEEK_OF_YEAR | |
$S3SYNC --progress --acl-private put $DUMPPATH/$DUMPFILENAME.sql.gz $S3BUCKET_NAME/$DUMPFILENAME.sql.gz | |
rm $DUMPPATH/$DUMPFILENAME.sql.gz | |
#How to run? | |
# /bin/bash ambari_server_backup.sh ambari_user_name ambari_password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment