Last active
June 4, 2024 02:51
-
-
Save ajaxray/8719fe9d9f4dd4e7a37ad5f5624dd4c1 to your computer and use it in GitHub Desktop.
Backup MySQL database to MEGA.nz cloud 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 | |
# ---------------------------------------------------- | |
# A Shell script to take MySql database backup | |
# and upload to MEGA cloud storage using megatools | |
# ---------------------------------------------------- | |
# REQUIREMENTS : You should have - | |
# 1. Registered and verified MEGA account - https://mega.nz/ | |
# 2. Installed megatools - https://github.com/megous/megatools | |
# ---------------------------------------------------- | |
# This script is part of this tutorial - http://wp.me/p2nCeQ-a2 | |
# ---------------------------------------------------- | |
# CONFIG - Set you information here | |
db_user=root | |
db_pass=yourDbPassword | |
db_name=databaseName | |
mega_user=megaEmail@ddress | |
mega_pass=megaPasswrd | |
mega_path=/Root/DB_BACKUP | |
# NOTE: MEGA remote path should start with /Root/ | |
# Create a temporary file | |
tmpfile=$(mktemp) | |
printf "Created temporary file: ${tmpfile} \n" | |
# Create Database dump and write to tmp file | |
printf "Writing database dump to tmp file..." | |
mysqldump -u ${db_user} -p${db_pass} ${db_name} > ${tmpfile} | |
printf " Done. \n" | |
# Upload dump file to MEGA cloud storage | |
printf "Uploading at ${mega_path}/${db_name}_$(date '+%Y-%m-%d-%H-%M').sql \n" | |
# Comment out next line if directory is already created for mega_path | |
megamkdir -u ${mega_user} -p ${mega_pass} ${mega_path} | |
megaput --no-progress -u ${mega_user} -p ${mega_pass} --path ${mega_path}/${db_name}_$(date '+%Y-%m-%d-%H-%M').sql ${tmpfile} | |
printf "Cleanup... " | |
rm ${tmpfile} | |
printf " Done. \n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment