Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #mongo configs
- APP_NAME="xxxxxx"
- MONGO_DATABASE="xxxxxx"
- MONGO_HOST="127.0.0.1"
- MONGO_PORT="27017"
- MONGO_USERNAME="xxxx"
- MONGO_PASSWORD="xxxxx"
- #backup configs
- TIMESTAMP=`date +%F-%H%M`
- BACKUPS_DIR="/home/$USER/mongo-backups/$APP_NAME"
- BACKUP_NAME="$APP_NAME-$TIMESTAMP.gz"
- ARCHIVE_PATH="$BACKUPS_DIR/$BACKUP_NAME"
- #ftp configs
- FTP_HOST="xxxxxxx"
- FTP_USER="xxxxxxxxxx"
- FTP_PASSWD="xxxxxxx"
- #dump the DB to archive
- mkdir -p $BACKUPS_DIR
- mongodump --username $MONGO_USERNAME --password $MONGO_PASSWORD --authenticationDatabase $MONGO_DATABASE --db $MONGO_DATABASE --archive=$ARCHIVE_PATH --gzip
- #upload to FTP backup
- ftp -n $FTP_HOST <<END_SCRIPT
- quote USER $FTP_USER
- quote PASS $FTP_PASSWD
- binary
- lcd $BACKUPS_DIR
- put $BACKUP_NAME
- quit
- END_SCRIPT
- #delete older than 30 days local backups
- find $ARCHIVE_PATH -type f -name '*.gz' -mtime +30 -exec rm -f {} \;
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement