Last active
April 1, 2019 16:25
-
-
Save realtebo/ca6cf0cca8c372880c7945b76cebc581 to your computer and use it in GitHub Desktop.
Backup of mysql on gdrive on a debian
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 | |
DB_PASS="xxxxxxxxxxx" | |
ROOT_FOLDER="Mysql_Dump" | |
SERVER_NAME="Server_50" | |
mkdir -p ./$ROOT_FOLDER/$SERVER_NAME/$DB_NAME | |
TODAY=$(date +"%Y_%m-%d_%H_%M_%S") | |
DB_NAME=$1 | |
# This is the portion that do the backup | |
rm -rf ./$ROOT_FOLDER/$SERVER_NAME/$DB_NAME -rf | |
./dumper.sh localhost root "$DB_NAME" "$DB_PASS" "./$ROOT_FOLDER/$SERVER_NAME/$DB_NAME" | |
# This is the portion that compress files | |
cd ./$ROOT_FOLDER/$SERVER_NAME/$DB_NAME | |
tar -czvf ./$ROOT_FOLDER/$SERVER_NAME/$DB_NAME/$TODAY.tar.gz ./* --remove-file | |
# This is the portion that upload files | |
drive push ./$ROOT_FOLDER/$SERVER_NAME/$DB_NAME | |
# Cleanup | |
cd .. | |
rm -rf ./$ROOT_FOLDER/$SERVER_NAME/$DB_NAME | |
cd .. | |
cd .. | |
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 | |
# dump-tables-mysql.sh | |
# Descr: Dump MySQL table data into separate SQL files for a specified database. | |
# Usage: Run without args for usage info. | |
# Author: @Trutane | |
# Ref: http://stackoverflow.com/q/3669121/138325 | |
# Notes: | |
# * Script will prompt for password for db access. | |
# * Output files are compressed and saved in the current working dir, unless DIR is | |
# specified on command-line. | |
# | |
#[ $# -lt 4 ] && echo "Usage: $(basename $0) <DB_HOST> <DB_USER> <DB_NAME> <DB_PASS>" && exit 1 | |
echo "$(basename $0) host=$1 user=$2 db=$3 pass=<omitted_\$4> dir=$5" | |
DB_host=$1 | |
DB_user=$2 | |
DB=$3 | |
DB_pass=$4 | |
DIR=$5 | |
if [ -z "$4" ]; | |
then | |
echo "Missing DB passwords !" | |
exit 1 | |
fi | |
[ -n "$DIR" ] || DIR=. | |
test -d $DIR || mkdir -p $DIR | |
echo | |
echo "Dumping tables into separate SQL command files for database '$DB' into dir=$DIR" | |
tbl_count=0 | |
for t in $(mysql -NBA -h $DB_host -u $DB_user -p$DB_pass -D $DB -e 'show tables') | |
do | |
echo "DUMPING TABLE: $DB.$t" | |
mysqldump -h $DB_host -u $DB_user -p$DB_pass $DB $t | gzip > $DIR/$DB.$t.sql.gz | |
if [ "$?" != "0" ]; then | |
echo "Exiting due to an error" | |
exit 2; | |
fi | |
tbl_count=$(( tbl_count + 1 )) | |
done | |
echo "$tbl_count tables dumped from database '$DB' into dir=$DIR" | |
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 | |
# Installation | |
su | |
apt-get install software-properties-common dirmngr | |
apt-add-repository 'deb http://shaggytwodope.github.io/repo ./' | |
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7086E9CC7EC3233B | |
apt-get update | |
apt-get install drive | |
# Remain root user | |
cd /root | |
mkdir gdrive_mysql_backup | |
cd gdrive_mysql_backup | |
touch backupper.sh | |
chmod 744 backupper.sh | |
# copy backupper.sh content into the file using nano or vi | |
touch dumper.sh | |
chmod 744 backupper.sh | |
# copy dumper.sh content into the file using nano or vi | |
# Authorization | |
drive init | |
# Visit the link and paste the code in the console |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment