forked from Fascinated/docs
99 lines
2.9 KiB
Markdown
99 lines
2.9 KiB
Markdown
|
---
|
||
|
title: Docker application backup
|
||
|
description: How to backup a Docker application on Unraid
|
||
|
published: true
|
||
|
date: 2023-06-27T07:54:18.672Z
|
||
|
tags: linux, server, unraid, backup
|
||
|
editor: markdown
|
||
|
dateCreated: 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](https://forums.unraid.net/topic/48286-plugin-ca-user-scripts/).
|
||
|
- Now we need to create the script. Go to `Settings > User Utilites > User Scripts` and click `Add New Script`.
|
||
|
- Give the script a name, for example `Backup Docker Application`.
|
||
|
- Paste the following into the script:
|
||
|
|
||
|
```bash
|
||
|
#!/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 of Days to Keep Backups
|
||
|
days=30
|
||
|
|
||
|
# The user of your account
|
||
|
# Example: lee
|
||
|
user=""
|
||
|
|
||
|
# --- Backup Application ---
|
||
|
|
||
|
# Start notification
|
||
|
/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 gitea-"$now".tar "$applicationData"
|
||
|
|
||
|
# Set Permissions
|
||
|
chown "$user:$user" $applicationName-"$now".tar
|
||
|
|
||
|
# Cleanup old backups
|
||
|
find "$backupDirectory"* -type d -mtime +"$days" | xargs rm -rf
|
||
|
|
||
|
# Stop notification
|
||
|
/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 click `Apply`.
|
||
|
|
||
|
## 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)
|
||
|
|
||
|
```bash
|
||
|
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:
|
||
|
|
||
|
```bash
|
||
|
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.
|