Skip to content

Instantly share code, notes, and snippets.

@pujianto
Last active May 20, 2020 02:37
Show Gist options
  • Save pujianto/f612d90f3811bd5c5489af38887236e4 to your computer and use it in GitHub Desktop.
Save pujianto/f612d90f3811bd5c5489af38887236e4 to your computer and use it in GitHub Desktop.
Simple script to backup all mysql databases & store them on remote server (in silent mode)
#!/bin/sh
HOST="localhost"
USER="root"
PASSWORD="root"
DB="--all-databases"
DATE=`date +%Y-%m-%d.%H.%M.%S`
NAME="mysql.backup.${DB}.${DATE}.sql.gz"
COMMAND="mysqldump -h ${HOST} -u ${USER} -p$PASSWORD ${DB} | gzip -c > ${NAME}"
SCP_COMMAND="scp ${NAME} user@backup-server:/path/to/backup/folder/"
eval $COMMAND
if [ -e "$NAME" ]; then
# copy gzipped backup to remote server.
eval $SCP_COMMAND
# delete after copied to target server.
rm -rf $NAME
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment