Skip to content

appdata backup config

Drazzilb edited this page Feb 23, 2024 · 1 revision

Appdata Backup

Description

This script is designed to create backups of Docker Container appdata. The backups are saved to a specified destination directory. The script will determine the appropriate source path for the backup based upon if the container has a /config mapped to a directory it will use that directory as the appdata path. If the container will use a source directory if mapped to /mnt/user/appdata or /mnt/cache/appdata. The script will determine if a given list of containers are valid containers on the system. If a container is removed from the system or has a typo it will notify the user and remove the entry from the config file. The script will notify the user of containers that aren't apart of the backup process. There are options to add all new containers to the stop and backup option or to the backup without stopping the container. There are options to exclude certain containers from any of these processes that might be covered by other scripts (think plex). Includes error handling for invalid configurations. Uses command line tool 7Zip for compression, and it checks if it's installed before running the script.

This script performs the following actions

  • This is a bash script for creating Docker Container appdata backups
  • The backups are saved to a specified destination directory
  • The script will determine the appropriate source path for the backup based upon:
    • If the container has a /config mapped to a directory it will use that directory as the appdata path
    • If the container will use a source directory if mapped to:
      • /mnt/user/appdata
      • /mnt/cache/appdata
  • The script will determine if a given list of containers are valid containers on the system.
    • If a container is removed from the system or has a typo it will notify the user and remove the entry from the config file
  • The script will notify the user of containers that aren't apart of the backup process
    • There are options to add all new containers to the stop and backup option or to the backup without stopping the container
    • There are options to exclude certain containers from any of these processes that might be covered by other scripts (think plex)
  • Includes error handling for invalid configurations
  • Uses command line tool 7Zip for compression, and it checks if it's installed before running the script

Config File

destination_dir='/path/to/backup'           # Path to your backup folder
keep_backup=2                               # Number of days of backups you'd like to keep
compress=false                              # Due to the size of some backups, compress your backups down as much as possible use 7Zip
exclude_file='/path/to/exclude-file.txt'    # Location of your exclusion file.
add_to_stop=false                           # Add any new containers to your stop and backup list
add_to_no_stop=false                        # Add any new container to your backup without stopping list
dry_run=true                                # Test the script out to make sure everything is to your liking
quiet=false                                 # Run script without echoing actions.

#------------- DEFINE CONTAINERS TO BACKUP -------------#
# Define containers you wish to backup
# Enclose all containers with double quotes (only required if the container has two words) such as "My Container"
# Each container should be on its own line as shown below
# The # symbol at the beginning is only for commenting and will cause the script to pass over it if used on real contianers
stop_list=(
    # "Container 1"
    # "Container 2"
    # "Container 3"
)
no_stop_list=(
    # "Container 4"
    # "Container 5"
    # "Container 6"
)
# The script includes an ability to automatically add or notify you of containers that aren't in the stop or no_stop lists
# If you don't wish to be notified about them or have them added to those list, define them here
# An example would be plex, as I have a backup solution for plex I don't need to be notified about it not being in the list
exclusion_list=(
    # "Container 1"
    # "Container 2"
    # "Container 3"
    "plex"
)

# Define locations for appdata directories
# Default values are set for most unRAID systems. Touch if you know what you're doing
appdata_dir1="/mnt/user/appdata"
appdata_dir2="/mnt/cache/appdata"

#------------- DEFINE NOTIFICATION VARIABLES -------------#
# This section is not required
webhook=''                                  # Discord or Notifiarr webhook (Notifarr uses passthrough integration)
use_summary=false                           # Summarize your discord notification output
bar_color='ff0000'                          # Requires 6-digit hex color

#------------- DEFINE DISCORD ONLY VARIABLES -------------#
bot_name='Notification Bot'                 # Name your bot (Only used if using Discord webhook)

#------------- DEFINE NOTIFIARR ONLY VARIABLES -------------#
channel='0'                                 # Required if using Notifiarr is your webhook

#------------- DEFINE UNRAID ONLY VARIABLES -------------#
unraid_notify=false                         # Use unRAID's built in notifications

FAQ:

Why did you make this script?

For Unraid, the CA appstore has a neat piece of kit that allows for the backup and restoration of docker application data. The only aspect of it that I didn't like at the time of originally making this script was that when it made the backup it put everything into one archive file. Which if you have a very large appdata directory like I do (over 1T of data) then it can take quite a while to pull just one file out of an archive.
So I made this script (based upon This script) which archives each folder and stores it away just in case.

Why don't you just backup Plex with this script?

Short answer: no reason.
Long answer: Plex being the way it is has a lot of information that you might not deem necessary to backup but sometimes it would be nice to have. If you use this backup script on a very large Plex instance (such as mines). You'd find your self with script that would take quite some time to finish. This is why I mad a seperate Plex backup that could allow for a more refined approach to backing up Plex.

Why am I getting awk: not an option: -I in my console?

The -I inplace option is not supported by all versions of awk. It's a feature of gawk, the GNU implementation of awk. If you're using a different version, you might not have this option available.

If you're using gawk, make sure it's updated to the latest version. If you're not using gawk, you'll need to find a different way to achieve the same result. One common method is to write the output to a temporary file, then move that file to replace the original.

Short solution would be to install gawk through your system's package manager and make sure awk is up to date.