Skip to content

Instantly share code, notes, and snippets.

@nielsnuebel
Last active December 20, 2019 11:34
Show Gist options
  • Save nielsnuebel/ddb11e064e2f90cc2533fd5c552e0516 to your computer and use it in GitHub Desktop.
Save nielsnuebel/ddb11e064e2f90cc2533fd5c552e0516 to your computer and use it in GitHub Desktop.
backup.sh
#!/bin/bash
BACKUP="/var/www/vhosts/PATH/scripts/kicktemp/kicktemp.sql"
BACKUPZIP="/var/www/vhosts/PATH/scripts/kicktemp/backup.zip"
BACKUPPATH="/var/www/vhosts/PATH/dev.kicktemp.com/"
SCRIPTPATH="/var/www/vhosts/PATH/scripts/kicktemp/"
MUSER="DBUSER"
MPASS="DBPASS"
MDB="DATABASE"
MHOST="localhost"
# Detect paths
MYSQL=$(which mysql)
MYSQLDUMP="$(which mysqldump)"
AWK=$(which awk)
GREP=$(which grep)
# make sure we can connect to server
$MYSQL -u $MUSER -p$MPASS -h $MHOST -e "use $MDB" &>/dev/null
if [ $? -ne 0 ]
then
echo "Error - Cannot connect to mysql server using given username, password or database does not exits!"
exit 1
fi
echo "Backup archiv"
if [ -f $BACKUPZIP ];
then
echo "Backupzip $BACKUPZIP remove"
rm -f $BACKUPZIP
else
echo "Backupzip $BACKUPZIP does not exists"
fi
echo "create backup.zip"
pushd $BACKUPPATH
zip -r $BACKUPZIP .
popd
if [ -f $BACKUP ];
then
echo "MySQL Backup $BACKUP remove"
rm -f $BACKUP
else
echo "MySQL Backup $BACKUP does not exists"
exit 3
fi
echo "Begin MySQL Backup $BACKUP"
$MYSQLDUMP -u $MUSER -p$MPASS -h $MHOST $MDB > kicktemp.sql
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment