Last active
April 25, 2016 14:24
-
-
Save diegargon/0a1d8f636368a9e9b3a57786402418ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# | |
# diegargon http/mail: diego.envigo.net | |
# Simple bash script for backup a sql database | |
# This script need Dropbox_Uploader https://github.com/andreafabrizi/Dropbox-Uploader | |
# | |
# Warning: zip/password its a bad option if you want protect sensitive data | |
#BEGIN CONFIG | |
TMP_DIR="/tmp/" | |
DB_USER="" | |
DB_PASSWORD="" | |
DB_NAME="" | |
DB_HOST="localhost" | |
DATE=`date +%d_%m_%Y` | |
PREFIX="db.$DB_NAME.$DATE" | |
#Dropbox folder | |
DROPBOX_DEST="" | |
ZIP_PASSWORD="" | |
#Dropbox_uploader path | |
UPLOADER_PATH="dropbox_uploader.sh" | |
#END CONFIG | |
SQL_FILE="$TMP_DIR.$PREFIX.sql" | |
BACKUP_FILE_TAR="$TMP_DIR.$PREFIX.tar" | |
BACKUP_FILE_ZIP="$TMP_DIR$PREFIX.tar.zip" | |
mysqldump -h "$DB_HOST" -u "$DB_USER" --password="$DB_PASSWORD" "$DB_NAME" > "$SQL_FILE" | |
if [ ! "$?" ] | |
then | |
echo "Mysqldump error on $DB_NAME, backup not done" | |
exit 1 | |
fi | |
tar cvf "$BACKUP_FILE_TAR" "$SQL_FILE" &> /dev/null | |
if [ ! "$?" ] | |
then | |
echo "tar error doing the $DB_NAME backup, backup not done" | |
rm -f "$SQL_FILE" | |
exit 1 | |
fi | |
zip -P "$ZIP_PASSWORD" -r "$BACKUP_FILE_ZIP" "$BACKUP_FILE_TAR" &> /dev/null | |
if [ ! "$?" ] | |
then | |
echo "zip error doing the $DB_NAME backup, backup not done" | |
rm -f "$SQLFILE" "$BACKUP_FILE_TAR" | |
exit 1 | |
fi | |
"$UPLOADER_PATH" upload "$BACKUP_FILE_ZIP" "$DROPBOX_DEST"/$PREFIX &> /dev/null | |
if [ ! "$?" ] | |
then | |
echo "Uploading error doing the $DB_NAME backup, backup not done" | |
rm -f "$SQL_FILE" "$BACKUP_FILE_TAR" "$BACKUP_FILE_ZIP" | |
exit 1 | |
fi | |
rm -f "$SQL_FILE" "$BACKUP_FILE_TAR" "$BACKUP_FILE_ZIP" | |
echo "Succesful uploading the $DB_NAME backup to $DROPBOX_DEST/$PREFIX"; | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment