Skip to content

Instantly share code, notes, and snippets.

@mattantonelli
Created April 7, 2021 18:15
Show Gist options
  • Select an option

  • Save mattantonelli/d5d9aa4c5f1e2c7356c83b90b400dfec to your computer and use it in GitHub Desktop.

Select an option

Save mattantonelli/d5d9aa4c5f1e2c7356c83b90b400dfec to your computer and use it in GitHub Desktop.
Set up automatic MySQL/MariaDB backups with AutoMySQLBackup

1. Download and configure AutoMySQLBackup

mkdir /opt/automysqlbackup
cp /opt/automysqlbackup
wget https://sourceforge.net/projects/automysqlbackup/files/latest/download -O automysqlbackup.tar.gz
tar -xvf automysqlbackup.tar.gz
vim myserver.conf # Configure as needed

2. Create a script for running the backups

/opt/automysqlbackup/backup.sh

#!/bin/sh

/opt/automysqlbackup/automysqlbackup /opt/automysqlbackup/myserver.conf

chown root.root /opt/backup/mysql/* -R
find /opt/backup/mysql/* -type f -exec chmod 400 {} \;
find /opt/backup/mysql/* -type d -exec chmod 700 {} \;

3. Create the backup directory and test the script

mkdir /opt/backup/mysql/
chmod 700 backup.sh
./backup.sh

4. Set up a daily cron to execute the backup script

/etc/crontab

  0  0  *  *  * root /opt/automysqlbackup/backup.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment