Backups MySQL/MariaDB tables and views separately with mysqldump. Each table/structure as single file within a tgz archive.
- Dumps Tables+Views separately (two files for each database)
- Suitable to use with small Databases < 1GB
- Exclude Databases from backup
- Backups are stored as compressed
.tgz
archives - Backup multiple database instances
- Cleanup of old backups using
find
- Custom options
- Uses debian-sys-maint user or a dedicated backup account
- Suitable to use with MySQL or MariaDB (both shipped with mysqldump)
- Optional file encryption via
gpg
using a publickey file
apt-get update
apt-get install mysql-mariadb-snapshot
Store the backups in /backup/mysql
mkdir -p /backup/mysql
Edit /etc/mysql-mariadb-snapshot/backup.conf
# bin locations
MYSQL_BIN=/usr/bin/mysql
MYSQLDUMP_BIN=/usr/bin/mysqldump
# backup location
MYSQL_BACKUP_LOCATION=/backup/mysql
# lifetime in days
MYSQL_BACKUP_LIFETIME=200
# filename - $NOW is defined as $(date +"%d-%m-%Y")
MYSQL_BACKUPFILE=mysql.$NOW.tgz
# tmp dir
MYSQL_TMP_DIR=/tmp/mysqldump
...
Example: Run Backup every day at 4:15
Note: in case you want to use another account then debian-sys-maint it is not required to run this script as root!
echo "15 4 * * * root /usr/bin/mysql-mariadb-snapshot /etc/mysql-mariadb-snapshot/backup.conf" > /etc/cron.d/mysql-mariadb-snapshot
mysql-mariadb-snapshot comes with a systemd service and timer. You can easily modify the scripts to match your needs (backup schedule, config path).
The service file is designed to work on per-instance base and uses the instance name as config file name /etc/mysql-mariadb-snapshot/%I.conf
Defaults
/lib/systemd/system/mysql-mariadb-snapshot.timer
/lib/systemd/system/mysql-mariadb-snapshot.service
Example: Run Backup every day at 4:30
File: /etc/systemd/system/mysql-mariadb-snapshot.timer
[Unit]
Description=mysql-mariadb-snapshot task daily
[Timer]
# Run at 04:30 am
OnCalendar=04:30
# do NOT start backup immediately if its missed (servers..)
Persistent=false
# linked unit instance -> use config file `/etc/mysql-mariadb-snapshot/backup.conf`
Unit=mysql-mariadb-snapshot@backup.service
[Install]
WantedBy=timers.target
mysql-mariadb-snapshot <config>
The backup - this means every single file within the tar archive - can optionally encrypted using a gnupg publickey. You should be familar with gnupg/openpgp before using this feature - otherwise the backups may become inaccesible.
Export a public key
gpg \
--no-options \
--export \
"246C BBDF 5D82 D7CC 786B 6D6D 3693 5688 EC2C 82E9" > publickey.gpg
Configuration
...
# optional gpg encryption
GPG_RECIPIENT="246C BBDF 5D82 D7CC 786B 6D6D 3693 5688 EC2C 82E9"
GPG_PUBLICKEY="/etc/mariadb/backupkey.gpg"
Tested with:
- Debian jessie
- Debian stretch
- Debian buster
The .deb package is automatically generated via a Continuous Delivery Pipeline - please do not build packages manually!
MYSQL-MARIADB-SNAPSHOT is OpenSource and licensed under the Terms of Mozilla Public License 2.0. You're welcome to contribute