MySQL Full Backup Bash Script

This simple Linux BASH script creates a Full-Dump of the database in MySQL on a file, the script can be used later for some cronjobs.

MySQL Full Backup Bash Script

backup-database-garanet

GitHub https://github.com/garanet/MySQL-bkp-script.git

  • Create a folder / backup.
  • Place the following script named ‘full-db-mysql.sh’ in the newly created folder.

#!/bin/bash
# www.garanet.net
# MySQL Full Backup Bash Script
# https://github.com/garanet/MySQL-bkp-script.git

# Define variables
my_user="root"
my_password="secret"
dumpname="/backup/dump.sql"

# Backup Databases.
/usr/bin/mysqldump -A --lock-tables=false --user=${my_user} --password=${my_password} > ${dumpname}; 
# Compress dump
tar cfz /backup/dump.sql.tar.gz ${dumpname}; 
# Delete old
rm ${dumpname};

  • Check that the script owner is root and change the permissions to 744.
  • As root, run the script with the command:: # sh full-db-mysql.sh.