Created
March 8, 2019 01:49
-
-
Save fatchan/095aff5a7aac67caa6878e381e53544c to your computer and use it in GitHub Desktop.
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment