Skip to content

Commit a0a8c18

Browse files
authored
Merge pull request #14 from 007revad/develop
Develop
2 parents 82a16a4 + c1cfe32 commit a0a8c18

4 files changed

Lines changed: 42 additions & 3 deletions

File tree

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v1.1.6
2+
- Added KeepQty setting to delete old backups and only keep the latest N backups.
3+
- KeepQty=5 would keep just the latest 5 backups.
4+
15
v1.0.5
26
- Bug fix for default conf file. Double quotes not needed and cause issue #11
37
- Updated Restore_Linux_Plex_Backup.sh to handle reading settings from conf file with spaces and no double quotes.

Linux_Plex_Backup.sh

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# shellcheck disable=SC2317,SC2181
33
#--------------------------------------------------------------------------
44
# 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
66
#
77
# MUST be run by a user in sudo, sudoers or wheel group, or as root
88
#
@@ -18,14 +18,15 @@
1818
# Script verified at https://www.shellcheck.net/
1919
#--------------------------------------------------------------------------
2020

21-
scriptver="v1.0.5"
21+
scriptver="v1.1.6"
2222
script=Linux_Plex_Backup
2323

2424

2525
# Read variables from backup_linux_plex.config
2626
Backup_Directory=""
2727
Name=""
2828
LogAll=""
29+
KeepQty=""
2930
if [[ -f $(dirname -- "$0";)/backup_linux_plex.config ]];then
3031
# shellcheck disable=SC1090,SC1091
3132
while read -r var; do
@@ -390,6 +391,33 @@ echo "Starting Plex..." |& tee -a "${Log_File}"
390391
systemctl start plexmediaserver
391392

392393

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+
393421
#--------------------------------------------------------------------------
394422
# Append the time taken to stdout and log file
395423

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ Set Name= to distro, hostname or you can set a 'nickname'. If Name= is blank the
6363

6464
The LogAll setting enables, or disables, logging every file that gets backed up. Set LogAll= to yes or no. Blank is the same as no.
6565

66+
The KeepQty setting tells the script to keep only keep the latest N backups (and delete older backups).
67+
6668
```YAML
6769
Name=distro
6870
LogAll=no
71+
KeepQty=5
6972
```
7073

7174
### Requirements

backup_linux_plex.config

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# https://github.com/007revad/Linux_Plex_Backup
55
#-------------------------------------------------------------------------
66

7-
# Set location to save tgz file to
7+
# Set location to save tgz file to.
88
Backup_Directory=/share/Backups/Plex_Backup
99

1010
# The script gets the distro and hostname for logging and the backup file name.
@@ -16,3 +16,7 @@ Name=distro
1616
# Set LogAll= to yes or no. Blank is the same as no.
1717
LogAll=no
1818

19+
# Delete old backups.
20+
# Set KeepQty= to the number of backups to keep.
21+
KeepQty=5
22+

0 commit comments

Comments
 (0)