├── README.md ├── backup_all_appdata ├── backup_flashdrive ├── backup_plex_dbs ├── backup_plexdata └── backup_select_appdata /README.md: -------------------------------------------------------------------------------- 1 | ## Please note that these scripts are tested by me for my use cases. They very well may work for you but I have not thoroughly tested these scripts under all conditions. Please test and use at your own risk. 2 | 3 | # Support 4 | 5 | If you find these scripts helpful, consider buying me a coffee or beer to show your appreciation. https://www.buymeacoffee.com/iamspartacus 6 | 7 | # Unraid User Scripts 8 | 9 | Various bash scripts to be used in the User Scripts plugin in Unraid 10 | 11 | 12 | ## Backup Scripts 13 | 14 | ### backup_all_appdata 15 | 16 | This script creates an individual tar file for each docker appdata directory found in your appdata path. Furthermore, it stops and restarts each container before and after backup if the container was running at the time of the backup. 17 | 18 | ### backup_flashdrive 19 | 20 | This script creates a dated tar file of the Unraid USB flash drive. 21 | 22 | ### backup_plex_db 23 | 24 | This script stops the plex container and copies the main plex db file to a backup location of your choosing before restarting the container. 25 | 26 | ### backup_plexdata 27 | 28 | This script creates an individual tar.gz file for all the plexdata that you redirect to be outside of your regular plex appdata directory. This is useful for making your appdata backups much smaller as to not capture directories like Media and Transcoder Cache that can take up huge amounts of space but is not mission critical for most. 29 | 30 | ### backup_select_appdata 31 | 32 | This script creates an invididual tar file for each docker appdata directory that you define (needs both container name and path to it's appdata). Furthermore, it stops and restarts each container before and after backup if the container was running at the time of the backup. 33 | 34 | ## Usage 35 | 36 | Create a new User script and paste script text in 37 | 38 | ### Example Cron Schedules 39 | 40 | Cron schedule to run script every morning at 5:00am 41 | 42 | ```bash 43 | 0 5 * * * 44 | ``` 45 | 46 | Cron schedule to run script every Monday morning at 5:00am 47 | 48 | ```bash 49 | 0 5 * * 1 50 | ``` 51 | 52 | Cron schedule to run script every morning at 5:00am except Monday 53 | 54 | ```bash 55 | 0 5 * * 0,2-6 56 | ``` 57 | -------------------------------------------------------------------------------- /backup_all_appdata: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #--DEFINE VARIABLES--# 4 | 5 | # Set Appdata Directory (must include trailing /) 6 | appdataDirectory='/PATH/TO/YOUR/DOCKER/APPDATA/' 7 | 8 | # Set Backup Directory (must include trailing /) 9 | backupDirectory='/PATH/TO/YOUR/BACKUP/DIRECTORY/' 10 | 11 | # Set Number of Days to Keep Backups 12 | days=60 13 | 14 | 15 | #--START SCRIPT--# 16 | /usr/local/emhttp/plugins/dynamix/scripts/notify -s "AppData Backup" -d "Backup of ALL Appdata starting." 17 | 18 | now="$(date +"%Y-%m-%d"@%H.%M)" 19 | mkdir """$backupDirectory"""$now"" 20 | 21 | for path in "$appdataDirectory"* 22 | 23 | do 24 | name="$(basename "$path")" 25 | path=""$appdataDirectory""$name"" 26 | 27 | cRunning="$(docker ps -a --format '{{.Names}}' -f status=running)" 28 | 29 | if echo $cRunning | grep -iqF $name; then 30 | echo "Stopping $name" 31 | docker stop -t 60 "$name" 32 | cd ""$backupDirectory""$now"" 33 | tar cWfC "./$name.tar" "$(dirname "$path")" "$(basename "$path")" 34 | echo "Starting $name" 35 | docker start "$name" 36 | else 37 | cd ""$backupDirectory""$now"" 38 | tar cWfC "./$name.tar" "$(dirname "$path")" "$(basename "$path")" 39 | echo "$name was stopped before backup, ignoring startup" 40 | fi 41 | 42 | done 43 | 44 | #Cleanup Old Backups 45 | find "$backupDirectory"* -type d -mtime +"$days" -exec rm -rf {} + 46 | 47 | #Stop Notification 48 | /usr/local/emhttp/plugins/dynamix/scripts/notify -s "AppData Backup" -d "Backup of ALL Appdata complete." 49 | -------------------------------------------------------------------------------- /backup_flashdrive: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #--DEFINE VARIABLES--# 4 | 5 | # Set Flashdrive Backup Directory (must include trailing /) 6 | flashbackupDirectory='/PATH/TO/YOUR/BACKUP/DIRECTORY/' 7 | 8 | # Set Number of Days to Keep Backups 9 | days=365 10 | 11 | 12 | #--START SCRIPT--# 13 | /usr/local/emhttp/plugins/dynamix/scripts/notify -s "FlashDrive Backup" -d "Backup of FlashDrive starting." 14 | 15 | tar cfW """$flashbackupDirectory"""flash$(date +"%Y-%m-%d")"".tar /boot 16 | 17 | #Cleanup Old Backups 18 | find "$flashbackupDirectory"* -type f -mtime +"$days" -exec rm -rf {} + 19 | 20 | #Stop Notification 21 | /usr/local/emhttp/plugins/dynamix/scripts/notify -s "FlashDrive Backup" -d "Backup of FlashDrive complete." 22 | -------------------------------------------------------------------------------- /backup_plex_dbs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Set Appdata Directory (must include trailing /) 4 | plexdbDirectory='/PATH/TO/YOUR/PLEX/DATABASES/DIRECTORY/' 5 | 6 | # Set Backup Directory (must include trailing /) 7 | backupDirectory='/PATH/TO/YOUR/BACKUP/DIRECTORY/' 8 | 9 | # Set Number of Days to Keep Backups 10 | days=365 11 | 12 | 13 | #--START SCRIPT--# 14 | /usr/local/emhttp/plugins/dynamix/scripts/notify -s "Plex DB Backup" -d "Backup of Plex DB's starting." 15 | 16 | docker stop plex 17 | cp -a "$plexdbDirectory"com.plexapp.plugins.library.db "$backupDirectory"com.plexapp.plugins.library-$(date +"%Y-%m-%d@%H.%M").db 18 | cp -a "$plexdbDirectory"com.plexapp.plugins.library.blobs.db "$backupDirectory"com.plexapp.plugins.library.blobs-$(date +"%Y-%m-%d@%H.%M").db 19 | docker start plex 20 | 21 | #Cleanup Old Backups 22 | find "$backupDirectory"* -type d -mtime +"$days" -exec rm -rf {} + 23 | 24 | #Stop Notification 25 | /usr/local/emhttp/plugins/dynamix/scripts/notify -s "Plex DB Backup" -d "Backup of Plex DB's complete." 26 | -------------------------------------------------------------------------------- /backup_plexdata: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #--DEFINE VARIABLES--# 4 | 5 | # Set Plexdata Directory (must include trailing /) 6 | plexdataDirectory='/PATH/TO/YOUR/PLEXDATA/' 7 | 8 | # Set Backup Directory (must include trailing /) 9 | backupDirectory='/PATH/TO/YOUR/BACKUP/DIRECTORY/' 10 | 11 | # Set Number of Days to Keep Backups 12 | days=45 13 | 14 | 15 | #--START SCRIPT--# 16 | /usr/local/emhttp/plugins/dynamix/scripts/notify -s "Plexdata Backup" -d "Backup of Plexdata starting." 17 | 18 | now="$(date +"%Y-%m-%d"@%H.%M)" 19 | mkdir ""$backupDirectory""$now"" 20 | 21 | #Plexdata Backup (excluding Transcode directory from backups) 22 | cd ""$backupDirectory""$now"" 23 | tar -cf plexdata-"$now".tar --exclude "$plexdataDirectory"Transcode "$plexdataDirectory" 24 | #Uncomment below line to use pigz to compress the file afterwards and delete the original .tar file (will use max CPU threads unless otherwise specified with -p#) 25 | #pigz -9 plexdata-"$now".tar 26 | 27 | #Cleanup Old Backups 28 | find "$backupDirectory"* -type d -mtime +"$days" | xargs rm -rf 29 | 30 | #Stop Notification 31 | /usr/local/emhttp/plugins/dynamix/scripts/notify -s "Plexdata Backup" -d "Backup of Plexdata complete." 32 | -------------------------------------------------------------------------------- /backup_select_appdata: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #--DEFINE VARIABLES--# 4 | 5 | # Containers to backup and their appdata paths 6 | list=( 7 | container01_name /PATH/TO/YOUR/CONTAINER01/APPDATA 8 | container02_name /PATH/TO/YOUR/CONTAINER02/APPDATA 9 | container03_name /PATH/TO/YOUR/CONTAINER03/APPDATA 10 | ) 11 | 12 | # Set Backup Directory (must include trailing /) 13 | backupDirectory='/PATH/TO/YOUR/BACKUP/DIRECTORY/' 14 | 15 | # Set Number of Days to Keep Backups 16 | days=15 17 | 18 | #--START SCRIPT--# 19 | /usr/local/emhttp/plugins/dynamix/scripts/notify -s "AppData Backup" -d "Backup of ALL Appdata starting." 20 | 21 | now="$(date +"%Y-%m-%d"@%H.%M)" 22 | 23 | mkdir """$backupDirectory"""$now"" 24 | 25 | for (( i = 0; i < ${#list[@]}; i += 2 )) 26 | do 27 | name=${list[i]} path=${list[i+1]} 28 | 29 | cRunning="$(docker ps -a --format '{{.Names}}' -f status=running)" 30 | 31 | if echo $cRunning | grep -iqF $name; then 32 | echo "Stopping $name" 33 | docker stop -t 60 "$name" 34 | cd ""$backupDirectory""$now"" 35 | tar cWfC "./$name.tar" "$(dirname "$path")" "$(basename "$path")" 36 | echo "Starting $name" 37 | docker start "$name" 38 | else 39 | cd ""$backupDirectory""$now"" 40 | tar cWfC "./$name.tar" "$(dirname "$path")" "$(basename "$path")" 41 | echo "$name was stopped before backup, ignoring startup" 42 | fi 43 | 44 | done 45 | 46 | #Cleanup Old Backups 47 | find "$backupDirectory"* -type d -mtime +"$days" -exec rm -rf {} + 48 | 49 | #Stop Notification 50 | /usr/local/emhttp/plugins/dynamix/scripts/notify -s "AppData Backup" -d "Backup of ALL Appdata complete." 51 | --------------------------------------------------------------------------------