Categories: Development

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.

Share

Recent Posts

FastAPI, SQLAlchemy & Uvicorn

A FastAPI, SQLAlchemy & Uvicorn to fetch a Google Sheet A FastAPI, SQLAlchemy & Uvicorn to fetch a Google Sheet… Read More

Client TrueNas & Ldap with python Flask

A webtool in Python Flask that creates an LDAP user and his TrueNAS shares pool in ISCSI or NFS. There… Read More

Simple Terraform configuration

A Terraform configuration that provisions the following infrastructure: A VPC with: Public subnets for external resources. Private subnets for internal… Read More