Skip to content

Instantly share code, notes, and snippets.

@gchristofferson
Created December 21, 2018 00:41
Show Gist options
  • Save gchristofferson/6400d13aabcd605c7d312daf115be093 to your computer and use it in GitHub Desktop.
Save gchristofferson/6400d13aabcd605c7d312daf115be093 to your computer and use it in GitHub Desktop.
This script will make a backup of the database in the backup directory
#!/bin/sh
# This script will make a backup of the databases
username="<username>"
password="<password>"
host="<hostname>"
dbname="<database name>"
current_date=`date +"%Y-%m-%d-%T"`
file_name="$dbname""_""$current_date"
file_name="${file_name/:/}"
file_name="${file_name/:/}.sql"
echo $file_name
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
if [[ $SCRIPTPATH != "/home/dh_mcbjqv/db_backup" ]]
then
echo "We are in the wrong directory"
echo "$( cd "$(dirname "$0")" ; pwd -P )"
echo "changing directories"
cd /home/dh_mcbjqv/db_backup
else
echo "We are in the right directory"
fi
echo $SCRIPTPATH
mysqldump --opt --user=$username --password=$password --host=$host $dbname > $file_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment