|
2 | 2 | # shellcheck disable=SC2317,SC2181 |
3 | 3 | #-------------------------------------------------------------------------- |
4 | 4 | # Backup Linux Plex Database to tgz file in Backup folder. |
5 | | -# v1.0.5 09-Nov-2024 007revad |
| 5 | +# v1.1.6 04-Nov-2024 007revad |
6 | 6 | # |
7 | 7 | # MUST be run by a user in sudo, sudoers or wheel group, or as root |
8 | 8 | # |
|
18 | 18 | # Script verified at https://www.shellcheck.net/ |
19 | 19 | #-------------------------------------------------------------------------- |
20 | 20 |
|
21 | | -scriptver="v1.0.5" |
| 21 | +scriptver="v1.1.6" |
22 | 22 | script=Linux_Plex_Backup |
23 | 23 |
|
24 | 24 |
|
25 | 25 | # Read variables from backup_linux_plex.config |
26 | 26 | Backup_Directory="" |
27 | 27 | Name="" |
28 | 28 | LogAll="" |
| 29 | +KeepQty="" |
29 | 30 | if [[ -f $(dirname -- "$0";)/backup_linux_plex.config ]];then |
30 | 31 | # shellcheck disable=SC1090,SC1091 |
31 | 32 | while read -r var; do |
@@ -390,6 +391,33 @@ echo "Starting Plex..." |& tee -a "${Log_File}" |
390 | 391 | systemctl start plexmediaserver |
391 | 392 |
|
392 | 393 |
|
| 394 | +#-------------------------------------------------------------------------- |
| 395 | +# Delete old backups |
| 396 | + |
| 397 | +if [[ $KeepQty -gt "0" ]]; then |
| 398 | + readarray -t array < <(ls "$Backup_Directory" |\ |
| 399 | + grep -E "${Nas}"'_[0-9]{8,}(-[0-9]{4,})?_Plex_.*\.tgz' | head -n -"$KeepQty") |
| 400 | + |
| 401 | + if [[ "${#array[@]}" -gt "0" ]]; then |
| 402 | + echo -e "\nDeleting old backups" |& tee -a "${Log_File}" |
| 403 | + for file in "${array[@]}"; do |
| 404 | + if [[ -f "$Backup_Directory/$file" ]]; then |
| 405 | + echo "Deleting $file" |& tee -a "${Log_File}" |
| 406 | + rm "$Backup_Directory/$file" |
| 407 | + fi |
| 408 | + if [[ -f "$Backup_Directory/${file%.tgz}.log" ]]; then |
| 409 | + echo "Deleting ${file%.tgz}.log" |& tee -a "${Log_File}" |
| 410 | + rm "$Backup_Directory/${file%.tgz}.log" |
| 411 | + fi |
| 412 | + if [[ -f "$Backup_Directory/${file%.tgz}_ERROR.log" ]]; then |
| 413 | + echo "Deleting ${file%.tgz}_ERROR.log" |& tee -a "${Log_File}" |
| 414 | + rm "$Backup_Directory/${file%.tgz}_ERROR.log" |
| 415 | + fi |
| 416 | + done |
| 417 | + fi |
| 418 | +fi |
| 419 | + |
| 420 | + |
393 | 421 | #-------------------------------------------------------------------------- |
394 | 422 | # Append the time taken to stdout and log file |
395 | 423 |
|
|
0 commit comments