Last active
May 1, 2023 04:33
-
-
Save virbo/671e1ae447be08f45f5d59c79a27a6bd to your computer and use it in GitHub Desktop.
Bash Script Backup DB and File Website to Kilat Storage
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 | |
# Backup Mysql DB, Wordpress (https://dutainformasi) | |
# Author Yusuf Ayuba (hello@yusufayuba.net) | |
#override endpoint aws amazone s3 with endpoint s3 kilatstorage | |
alias aws='aws --endpoint-url https://s3-id-jkt-1.kilatstorage.id' | |
# inisial variabel | |
tgl=$(date +'%H:%M:%S_%d-%m-%Y') | |
USER_DB="user_db" | |
PASS_DB="pass_db" | |
DB_NAME="db_name" | |
BUCKET_NAME="bucket_name" | |
LOKASI_FILE_WEB="lokasi_file_web" #(example: /home/user/public_html) | |
#inisialisasi variabel bot telegram (optional) | |
TOKEN="token telegram" | |
CHAT_ID="id telegram" | |
ENDPOINT="https://api.telegram.org/bot$TOKEN" | |
SEND_MESSAGE="$ENDPOINT/sendMessage" | |
PESAN="Database beserta file website telah dibackup" | |
# proses backup | |
mysqldump -h localhost -u $USER_DB -p"$PASS_DB" $DB_NAME | aws s3 cp - s3://$BUCKET_NAME/$tgl.sql | |
# proses backup file-file website | |
tar cv $LOKASI_FILE_WEB/* | gzip | aws s3 cp - s3://$BUCKET_NAME/$tgl.tar.gz | |
# send message to Telegram | |
curl -s -X GET $SEND_MESSAGE -d chat_id=$CHAT_ID -d text="$PESAN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment