UNRAID 6.7.1 easy way to backup and restore specific dockers


Recommended Posts

  • 1 month later...
10 hours ago, wgstarks said:

@JoeUnraidUser

I've been using your script successfully for several months but recently I just get line 2 permission denied when I try to run it.

 

813373757_ScreenShot2021-12-21at9_25_50PM.thumb.png.67b28ea83db01b7c17dec8026a25e1ab.png

 

user script-

#!/bin/bash
/mnt/user/backups/backupDockers.sh -b unifi binhex-radarr binhex-sonarr binhex-qbittorrentvpn jackett mariadb tautulli PlexMediaServer plex-utills


175.67 kB · 0 downloads


Fixed

 

On 11/2/2021 at 10:33 AM, wallas9512 said:

Thank fot all. For make this script persistent (and futur scripts).

 

Create folder with all script in /boot/config/scripts
Add User Script run "at first array start only" > rsync -hrltgoD --chown=root:root --chmod=ugo=rwx /boot/config/scripts/ /usr/local/bin

 

Thaks to all!

Worked great. Couldn’t just call the script in User Scripts though. Had to use /usr/local/bin/backupDockers.sh.

Link to comment
  • 2 weeks later...

For the life of me I cannot understand why this doesn't work for me. The file can no longer be downloaded, so on a Windows machine I opened Notepad++ copied the contents into a new file and saved as backupDockers.sh. I copied the file to X:\appdataBackup\containers\ this the path to the unRAID share where I have my weekly backups already going. I open terminal from the unRAID gui. I go to the path where I have the .sh file copied. I put this into the terminal window "backupDockers.sh -b -d /mnt/user/Backups/appdataBackup/containers/mariadb mariadb"

 

This is the response I get back from the terminal window "bash: ./backupDockers.sh: /bin/bash^M: bad interpreter: No such file or directory"

Link to comment
1 hour ago, FreddyGSanford said:

For the life of me I cannot understand why this doesn't work for me. The file can no longer be downloaded, so on a Windows machine I opened Notepad++ copied the contents into a new file and saved as backupDockers.sh. I copied the file to X:\appdataBackup\containers\ this the path to the unRAID share where I have my weekly backups already going. I open terminal from the unRAID gui. I go to the path where I have the .sh file copied. I put this into the terminal window "backupDockers.sh -b -d /mnt/user/Backups/appdataBackup/containers/mariadb mariadb"

 

This is the response I get back from the terminal window "bash: ./backupDockers.sh: /bin/bash^M: bad interpreter: No such file or directory"

I just tried downloading the file from the link and the download still works.

Link to comment
  • 11 months later...

At first. The Script is working like a charm...I'm recognize it's backup only the Container that are sitting in appdata. The Cache folders are not in the backup list. And its also not possible to backup there with direkt command. There are also showed in the backuplist.

 

./backupDockers.sh -l

 

Get only blank timestamps:

 

DATE: 2022-12-04-12-23-15-CET
DATE: 2022-12-04-12-23-15-CET

 

What can we do here? Correct the cache-dir not solve the problem.

 

cache="/mnt/cache"

 

Thanks in advance.

 

Edit: Its not backup all Docker Images that have some data in the cache directory.

Edited by Mustafa Aydin
Link to comment
On 12/4/2022 at 6:31 AM, Mustafa Aydin said:

At first. The Script is working like a charm...I'm recognize it's backup only the Container that are sitting in appdata. The Cache folders are not in the backup list. And its also not possible to backup there with direkt command. There are also showed in the backuplist.

 

./backupDockers.sh -l

 

Get only blank timestamps:

 

DATE: 2022-12-04-12-23-15-CET
DATE: 2022-12-04-12-23-15-CET

 

What can we do here? Correct the cache-dir not solve the problem.

 

cache="/mnt/cache"

 

Thanks in advance.

 

Edit: Its not backup all Docker Images that have some data in the cache directory.

 

I'm not sure what you are trying to do.

 

"./backupDockers.sh -l" only lists the dockers you have installed on the system, not the backups of the dockers.

 

You should never use /mnt/cache as your backup directory.  The backup will fail because it syncs the files to a folder called appdata in the backup directory.  appdata is usually located in /mnt/cache/appdata.  It would mean it is trying to overwrite itself.

Link to comment
  • 3 months later...

Not to bump an old thread, but is this still the best way to back up docker?  I want to back up all dockers before doing any updates (and be able to restore).  Lately most updates seem to break functionality and i'm sent on a several hour journey to figure out how to fix.  I wish we could roll back updates, but this method will have to suffice if its still the best way.

Link to comment
  • 6 months later...

Hi guys,

I use UserScripts to prepare/back up appdata (Dockers) and domains (VMs) and then i use Duplicacy to make backups. In Duplicacy i can then restore different versions from a dropdown. This way i can restore specific docker/VM back to Unraid. 

I'm an newbie at Unraid, rsync and tar so maybe this it totally wrong but it works for me.

Please tell me if you have some idea's on how to improve (or maybe tell me to scrap it all 😄)

 

 

DOCKERS
 

#!/bin/bash

# Get all running containers and store them in $CONTAINERS
mapfile -t CONTAINERS < <( docker inspect --format='{{.Name}}' $(docker ps -q --no-trunc) | cut -c2- )

# show in logrun
echo "Appdata backup started - Starting to shut down dockers"

# Show notification in Unraid (alert, warning, normal)
/usr/local/emhttp/webGui/scripts/notify -s "Notice [Script] -Appdata backup started" -i "normal" -d "Starting to shut down dockers"

# Stop all running containers
for container in "${CONTAINERS[@]}"; do
  echo "Stopping ${container}..."
  docker stop ${container} 1> /dev/null
done

# show in logrun
echo "Dockers shutted down. Starting backup"

# Show notification in Unraid (alert, warning, normal)
/usr/local/emhttp/webGui/scripts/notify -s "Warning [Script] -Appdata backup running" -i "warning" -d "Dockers shutted down. Starting backup"

# Backup appdata
echo "Backing up /mnt/user/appdata/"
rsync -a --delete /mnt/user/appdata/ /mnt/user/backups/appdatabackups/

# Show notification in Unraid (alert, warning, normal)
/usr/local/emhttp/webGui/scripts/notify -s "Warning [Script] -Appdata backup running" -i "warning" -d "Backup done. Starting dockers"

# Start all containers that were previously running
for container in "${CONTAINERS[@]}"; do
  echo "Starting ${container}..."
  docker start ${container} 1> /dev/null
done

# show in logrun
echo "Dockers started. Starting to tar files"

# Show notification in Unraid (alert, warning, normal)
/usr/local/emhttp/webGui/scripts/notify -s "Warning [Script] -Appdata backup running" -i "warning" -d "Dockers started. Starting to tar files"

# Compress appdata and remove original folders
find /mnt/user/backups/appdatabackups/ -type d -maxdepth 1 -mindepth 1 -exec tar zcvf {}.tar.gz {} --remove-files \;

# show in logrun
echo "Appdata backup done - Ready to do Duplicacy backup"

# Show notification in Unraid (alert, warning, normal)
/usr/local/emhttp/webGui/scripts/notify -s "Notice [Script] - Appdata backup done" -i "normal" -d "Ready to do Duplicacy backup"



VMs

 

#!/bin/bash

#Empty vm list
echo "" > /tmp/vms-running.txt

# show in logrun
echo "VMs backup started - Starting to shut down VMs"

# Show notification in Unraid (alert, warning, normal)
/usr/local/emhttp/webGui/scripts/notify -s "Notice [Script] -VMs backup started" -i "normal" -d "Starting to shut down VMs"

#Get all running vms except VM-TO-NOT-SHUTDOWN server
for VM in $(virsh list --state-running --name); do
  if [[ ! "$VM" == "VM-TO-NOT-SHUTDOWN" ]] ; then
    virsh shutdown "$VM"

#Write running vms to list
echo "$VM" >> /tmp/vms-running.txt

fi
done

# sleep if no vm is started to get next notice
sleep 5

# show in logrun
echo "VMs shutted down. Starting backup"

# Show notification in Unraid (alert, warning, normal)
/usr/local/emhttp/webGui/scripts/notify -s "Warning [Script] -VMs backup running" -i "warning" -d "VMs shutted down. Starting backup"

# Backup appdata
echo "Backing up /mnt/user/domains/"
rsync -a --delete /mnt/user/domains/ /mnt/user/backups/vmbackups/

# Show notification in Unraid (alert, warning, normal)
/usr/local/emhttp/webGui/scripts/notify -s "Warning [Script] -VMs backup running" -i "warning" -d "Backup done. Starting VMs"

#Get all running vms except backup server
for VM in $(cat /tmp/vms-running.txt); do
  virsh start "$VM"

done

# show in logrun
echo "VMs started. Starting to tar files"

# Show notification in Unraid (alert, warning, normal)
/usr/local/emhttp/webGui/scripts/notify -s "Warning [Script] -VMs backup running" -i "warning" -d "VMs started. Starting to tar files"

# Compress appdata and remove original folders
find /mnt/user/backups/vmbackups/ -type d -maxdepth 1 -mindepth 1 -exec tar zcvf {}.tar.gz {} --remove-files \;

# show in logrun
echo "VMs backup done - Ready to do Duplicacy backup"

# Show notification in Unraid (alert, warning, normal)
/usr/local/emhttp/webGui/scripts/notify -s "Notice [Script] - VMs backup done" -i "normal" -d "Ready to do Duplicacy backup"

 

Edited by Peterca
Link to comment
  • 1 month later...
On 3/10/2023 at 5:01 PM, trurl said:

CA Backup / Restore Appdata plugin has been updated since this old thread and is probably what most use

I might be wrong here and probably would like a dumb ass, but Appdata doesn't seem to be containing the ...how should I say this... the "installation files" (excuse me for the dirty Windows comparison, still learning Linux), with the Appdata being the config folder. I am guessing those are in the "docker image". Not really sure, I see some of my containers have many files and folders, some such as GluetunVPN only has 2 files in it's appdata folder.

So, to match the topic's subject line, how can I go about backing up a docker container entirely, say before update of container, and if the updates breaks something (often for me with my luck), restore the previous version? I am thinking about switching my cache drive to ZFS and adding another ZFS pool, so I could take such backups perhaps.

Link to comment
41 minutes ago, OrdinaryButt said:

So, to match the topic's subject line, how can I go about backing up a docker container entirely, say before update of container, and if the updates breaks something (often for me with my luck), restore the previous version?

Backup of appdata is the only files you need. If you need to install the container again from scratch you can do that from the previous apps section in the apps tab. You can install all of your containers in like 2 min from there if you need to, in a single click. And you be up an running with the same settings as before provided you have backups of your appdata. As all your container template settings are saved on the flash drive.

 

And with docker, roiling back to a previous version is so much easier then windows, or normal app install I should say (you can run docker on windows too) You just go to the docker template, switch to advanced view and put in the tag (version) you want in the repository filed. You can find all the tags for a container on dockerhub. No need to uninstall, just put in the tag hit apply and you're up in about 10 sec. 

Link to comment
57 minutes ago, strike said:

Backup of appdata is the only files you need. If you need to install the container again from scratch you can do that from the previous apps section in the apps tab. You can install all of your containers in like 2 min from there if you need to, in a single click. And you be up an running with the same settings as before provided you have backups of your appdata. As all your container template settings are saved on the flash drive.

 

And with docker, roiling back to a previous version is so much easier then windows, or normal app install I should say (you can run docker on windows too) You just go to the docker template, switch to advanced view and put in the tag (version) you want in the repository filed. You can find all the tags for a container on dockerhub. No need to uninstall, just put in the tag hit apply and you're up in about 10 sec. 

What if older version is removed from repo? I have trust issues with "the cloud"

Link to comment
3 minutes ago, OrdinaryButt said:

What if older version is removed from repo? I have trust issues with "the cloud"

Not very likely, but it could happen, I guess. In that case you can use docker directory instead of the default docker image, then backup those too in addition to appdata. 

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.