Skip to content
Snippets Groups Projects

Automated SQL Backup Script

A simple bash script, to automatically create SQL dumps on a daily basis, scheduled by systemd. It comes with a built-in mechanism to check and delete old backups.

Installing / Getting started

Clone the repository and execute the installation script.

sudo git clone https://git.slub-dresden.de/dbod/sql-backup.git /opt/sql-backup
sudo bash /opt/sql-backup/install.sh
systemctl enable sql-backup.service

After the repository is cloned, the installation script is executed. The script first triggers the update script and checks for repository updates. After that, it is copying the systemd service files (.service and .timer) to the appropriate path.

Initial Configuration

The backup script needs an SQL User, capable to lock and dump the databases, which should be backuped. In the standard configuration, the script trys to backup every single database on the server "localhost", using the user "root" without a password. This will most probably result in an error. See further on the Step Configuration.

Developing

To participate in the development of the project, you just need to clone the repository.

git clone https://git.slub-dresden.de/dbod/sql-backup.git
cd sql-backup

Features

Configuration

The script needs the following variables to work. Therefor a file named 'config.json' is loaded. If the file does not exist, a standard configuration will be loaded.

Variable type variable name default Value
SQL Server Hostname sqlHost localhost
SQL Server Port sqlPort 3306
User used to connect sqlUser root
List of Databases dbNames ($(mysql -u $sqlUser -e "SHOW DATABASES;"))
Backup Root Directory backupRoot /var/backups/sql/
Days to keep Backups backupRetainDays 30

Contributing

"If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome."

Links

Licensing

"The code in this project is licensed under MIT license."