Database backup using ssh linux

By November 11, 2011 My SQL
Here we are creating gz backup files using shell programming

step1 . create backup file backup.sh
step2. set cron job in control panel.

#!/bin/bash
### MySQL Server Login Info ###
MUSER=”user”
MPASS=”Password”
MHOST=”localhost”
MYSQL=”$(which mysql)”
MYSQLDUMP=”$(which mysqldump)”
BAK=”backup/mysql”
GZIP=”$(which gzip)”

NOW=$(date +”%d-%m-%Y”)

[ ! -d $BAK ] && mkdir -p $BAK || /bin/rm -f $BAK/*

FILE=$BAK/”databasename”.gz
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS “databasename” | $GZIP -9 > $FILE

Leave a Reply

37 + = 42

Open chat
💬 Need help?