3.0 KiB
3.0 KiB
title | description | published | date | tags | editor | dateCreated |
---|---|---|---|---|---|---|
Docker application backup | How to backup a Docker application on Unraid | true | 2023-06-27T07:54:18.672Z | linux, server, unraid, backup | markdown | 2023-06-27T07:54:18.672Z |
Docker application backup
This guide will show you how to backup a Docker application on Unraid. Tested on Unraid 6.12.1
Get Started
- Begin by installing the User Scripts plugin.
- Now we need to create the script. Go to
Settings > User Utilites > User Scripts
and clickAdd New Script
. - Give the script a name, for example
Backup Docker Application
. - Paste the following into the script:
#!/bin/bash
# --- DO NOT TOUCH ---
now="$(date +"%Y-%m-%d"@%H.%M)"
# --- Variables ---
# The name of the application
applicationName="application_name"
# The name of the backup
backupName="backup-$(date +%Y-%m-%d_%H-%M-%S)"
# Set the path to the application's data directory
applicationData="/mnt/user/appdata/application_name/"
# Set the path to the backup directory
# Example: /mnt/user/Storage/Backups/$applicationName/
backupDirectory=""
# Set Number backups to keep
backupsToKeep=30
# The user of your account
# Example: lee
user=""
# --- Backup Application ---
# Start notification
echo "Backup of $applicationName starting."
/usr/local/emhttp/plugins/dynamix/scripts/notify -s "$applicationName Backup" -d "Backup of $applicationName starting."
# Create backup directory
mkdir -p "$backupDirectory"
cd "$backupDirectory"
# Create the backup tarball
tar -cf "$applicationName-$now".tar "$applicationData"
# Set Permissions
chown "$user:$user" "$applicationName-$now".tar
# Cleanup old backups
for file in $(ls -t); do
if [[ $count -ge $backupsToKeep ]]; then
rm -- "$file"
echo "Deleted old backup: $file"
fi
((count++))
done
# Stop notification
echo "Backup of $applicationName completed!"
/usr/local/emhttp/plugins/dynamix/scripts/notify -s "$applicationName Backup" -d "Backup of $applicationName completed!"
-
You can now test the script by clicking
Run Script
. If everything is working correctly, you should see a notification in the top right corner of the screen. -
Now we need to set the script to run on a schedule. Next to
Run In Background
you will see a dropdown menu. Select how often you want it to run and clickApply
.
Restore a backup
- Delete the application's data directory.
- Copy the backup to the application's data directory. Move the backup with the following command: (or via the Unraid web interface)
mv <backup_name>.tar /mnt/user/appdata/application_name/
- To restore a backup, simply extract the tarball and copy the files to the application's data directory. You can extract the tarball by running the following command:
tar -xvf <backup_name>.tar
This command will extract the tarball to the current directory.
Finished
You have now successfully setup a backup script for your Docker application. You can view the backups in the directory you set in the script.