Automated MySQL Backups with Backupninja on Debian
Introduction
In today’s digital era, databases are at the core of information storage and management. From small businesses to global corporations, they contain vital data for daily operations and long-term success.
That’s why it’s essential to have a backup strategy that ensures protection against data loss, enables error recovery, and helps meet compliance requirements. Backups also allow developers to work with realistic staging environments without touching production data.
This tutorial walks you through deploying automated backups with Backupninja on Debian 11.
Requirements
- A machine running Debian 11
- An existing MySQL database
- Optionally, phpMyAdmin for administration
Installing Backupninja
Install via apt:
apt update
apt install backupninja -y
Verify installation:
backupninja --version
Key files created during setup:
/etc/backupninja.conf→ Global configuration/etc/backup.d/→ Where backup tasks are defined/etc/cron.d/backupninja→ Cron job running every hour
Configuring a backup task
Create /etc/backup.d/10-daily.mysql with restrictive permissions:
chmod 700 /etc/backup.d/10-daily.mysql
Example content:
databases = my_database
backupdir = /var/backups/mysql
hotcopy = no
sqldump = yes
compress = yes
dbhost = YOUR_SERVER_IP
dbusername = super_user
dbpassword = super_password
when = everyday at 01:00
Installing MySQL client
Since Backupninja relies on mysqldump, install the client package:
apt install default-mysql-client -y
Running tasks manually
Normally, cron will trigger Backupninja automatically, but you can run it manually:
backupninja -n
With debug enabled:
backupninja -n -d
The log output will confirm whether the dump succeeded.
Verification
Backups are stored at:
/var/backups/mysql/sqldump/my_database.sql.gz
Checking file presence and size ensures the backup completed successfully.
Technologies
Debian 11, Backupninja, MySQL