Created
January 23, 2024 22:46
-
-
Save jsupa/234b2153a7314bcaccf084a5e1c07fc3 to your computer and use it in GitHub Desktop.
mongo-backup.sh
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
# mogno dump to sftp server | |
#!/bin/bash | |
SFTP_STRING="username@storage1.hukot.net" | |
CURRENT_TIME=$(date "+%Y.%m.%d-%H.%M.%S") | |
BACKUP_DIR="/home/jsupa/zaloha" | |
# dump mongo | |
mongodump --out $BACKUP_DIR/dump | |
# zip dump | |
tar czf $BACKUP_DIR/$CURRENT_TIME.tar.gz $BACKUP_DIR/dump | |
# upload to sftp | |
sftp -v $SFTP_STRING <<EOF | |
cd data | |
put $BACKUP_DIR/$CURRENT_TIME.tar.gz | |
quit | |
EOF | |
# remove dump | |
rm -rf $BACKUP_DIR/dump | |
rm $BACKUP_DIR/$CURRENT_TIME.tar.gz | |
# send discord webhook | |
curl -H "Content-Type: application/json" -X POST -d '{"content":"MongoDB backup done"}' https://discord.com/api/webhooks/xxx | |
# close script | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment