Last active
May 20, 2020 02:37
-
-
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)
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/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