How to Shell script backup all Mysql Databases in Linux
This shell script will backup all current Mysql databases, compress(gzip) them and put them in a new folder named by current date (one directory per database).
#!/bin/bashPATH=/usr/sbin:/sbin:/bin:/usr/binMyUSER="your_db_user"MyPASS="your_db_password"MyHOST="your_db_host"SUBFOLDER="$(date +"%Y-%m-%d")"DEST="/somewhere/on/your/server"MDB="$DEST/backup/$SUBFOLDER"if [ ! -d $MDB ]then mkdir -p $MDB >/dev/null 2>&1 && echo "Directory $MDB created." || echo "Error: Failed to create $MDB directory."else echo "Error: $MDB directory exits!"fiNOW="$(date +"%Y-%m-%d_%H-%M-%S")"FILE=""DBS="$(mysql -u $MyUSER -h $MyHOST -p$MyPASS -Bse 'show databases')"for db in $DBSdo FILE="$MDB/$db.$NOW.sql.gz" mysqldump -u $MyUSER -h $MyHOST -p$MyPASS --complete-insert $db | gzip -9 > $FILE echo "Backup $FILE.....DONE"doneGD Star Rating
loading...
loading...
GD Star Rating
loading...
loading...

1 Trackback(s)