A bash script to be implemented as a cron job to backup your MySQL or MariaDB database.
First of all open the file and config:
backup_path="/backup/destination/folder"
user="YOUR DB USER"
password="YOUR DB PASSWORD"
host="YOUR HOST ADDRESS"
db_name="YOUR DB NAME"
keep_days=3
- keep_days is the amount of days that the script will keep files. (Default last 3 days files)
tables_truncate_after_dump
- It's an array of tables that will be truncated after the dump. Can be used if you want to truncate a log table. Do not split with comma use only white space. Example tables_truncate_after_dump("table1" "table2")
Be sure to give the correct permission to execute the bash with:
sudo chmod 700 /path/to/backup-mysql-mariadb.sh
sudo crontab -e
//Add this in the end of file
00 20 * * * /path/to/backup-mysql-mariadb.sh
In this case it’ll run every day at 8 PM.
Leandro Curioso leandro.curioso@gmail.com