Skip to main content

MySQL Database Backup

This guide requires MySQL or MariaDB installed on unRAID in a docker container and the User Scripts addon.

1. Map a backup folder

Edit your MySQL or MariaDB docker container and add a new Path variable for backups For example, /backup to /mnt/user/db-backups

2. Create a new script

Create a new script in the User Scripts plugin, and call it FileFlows-DB-Backup

3. Edit the Script

Edit the script by running

nano /boot/config/plugins/user.scripts/scripts/FileFlows-DB-Backup/script 

4. Code

Paste the following code replacing your database username and password and your backup location

#!/bin/bash

echo starting the backup

container=mariadb
user=root
password=password
dbname=FileFlows
backup=/backups
d=`date +%Y-%m-%d`

echo deleting old backups, older than 14 days
docker exec $container find $backup -type f -mtime +14 -exec rm -r {} +

echo about to backup $dbname
echo
docker exec $container mysqldump -u $user -p$password --databases $dbname --single-transaction --quick --result-file=$backup/$dbname-$d.sql

echo
echo finished backup up to $backup
Note

There is intentionally no space between -p and $password

5. Test the Script

Run the script from the User Scripts and check its output, confirm a new backup was saved to the backup path