MySQL Database Backup shell script
1 min read

MySQL Database Backup shell script

!/bin/bash

now=$(date +"%d-%m-%Y")
path="/path/to/folder"
muser="username"
mpassword="password"
mysqlfolder="mysqlbackup"
mysqlfile="mysqldumpall.$now.sql.gz"

echo "Dumping MySQL Databases to $path/$mysqlfolder"
mkdir -p $path/$mysqlfolder
mysqldump -u $muser -p$mpassword --all-databases | gzip -9 > $path/$mysqlfolder/$mysqlfile
echo "MySQL Database Backup Completed, size of the file is $(stat -c%s "$path/$mysqlfolder/$mysqlfile")"

This will backup your all databases in one dump sql file and compress it.Fill your values about your mysql server account, password and a path to write backup folder and files.You can add a cron job to make this process automatic at given times.Better safe than sorry.

Enjoying these posts? Subscribe for more