Refactor variable assignments and improve script readability in validate-plex-backups.sh and validate-plex-recovery.sh

- Changed inline variable assignments to separate declaration and assignment for clarity.
- Updated condition checks and log messages for better readability and consistency.
- Added a backup of validate-plex-recovery.sh for safety.
- Introduced a new script run-docker-tests.sh for testing setup in Docker containers.
- Enhanced ssh-login.sh to improve condition checks and logging functionality.
This commit is contained in:
Peter Wood
2025-06-05 17:14:02 -04:00
parent c3f237a321
commit 58b5dea8b4
31 changed files with 5024 additions and 539 deletions

View File

@@ -87,12 +87,17 @@ log_warning() {
# List available backups
list_backups() {
log_message "Available backups:"
find "$BACKUP_ROOT" -maxdepth 1 -type f -name "plex-backup-*.tar.gz" | sort -r | while read backup_file; do
local backup_name=$(basename "$backup_file")
local backup_date=$(echo "$backup_name" | sed 's/plex-backup-\([0-9]\{8\}\)_[0-9]\{6\}\.tar\.gz/\1/')
find "$BACKUP_ROOT" -maxdepth 1 -type f -name "plex-backup-*.tar.gz" | sort -r | while read -r backup_file; do
local backup_name
backup_name=$(basename "$backup_file")
local backup_date
backup_date=${backup_name#plex-backup-}
backup_date=${backup_date%_*.tar.gz}
if [[ "$backup_date" =~ ^[0-9]{8}$ ]]; then
local readable_date=$(date -d "${backup_date:0:4}-${backup_date:4:2}-${backup_date:6:2}" '+%B %d, %Y' 2>/dev/null || echo "Unknown date")
local file_size=$(du -h "$backup_file" 2>/dev/null | cut -f1)
local readable_date
readable_date=$(date -d "${backup_date:0:4}-${backup_date:4:2}-${backup_date:6:2}" '+%B %d, %Y' 2>/dev/null || echo "Unknown date")
local file_size
file_size=$(du -h "$backup_file" 2>/dev/null | cut -f1)
echo " $backup_name ($readable_date) - $file_size"
else
echo " $backup_name - $(du -h "$backup_file" 2>/dev/null | cut -f1)"
@@ -117,7 +122,7 @@ validate_backup() {
# List contents to verify expected files are present
log_message "Archive contents:"
tar -tzf "$backup_file" | while read file; do
tar -tzf "$backup_file" | while read -r file; do
log_success " Found: $file"
done
return 0
@@ -129,7 +134,8 @@ validate_backup() {
# Create backup of current Plex data
backup_current_data() {
local backup_suffix=$(date '+%Y%m%d_%H%M%S')
local backup_suffix
backup_suffix=$(date '+%Y%m%d_%H%M%S')
local current_backup_dir="$SCRIPT_DIR/plex_current_backup_$backup_suffix"
log_message "Creating backup of current Plex data..."
@@ -162,7 +168,8 @@ restore_files() {
fi
# Create temporary extraction directory
local temp_dir="/tmp/plex-restore-$(date +%Y%m%d_%H%M%S)"
local temp_dir
temp_dir="/tmp/plex-restore-$(date +%Y%m%d_%H%M%S)"
mkdir -p "$temp_dir"
log_message "Extracting backup archive..."
@@ -277,8 +284,8 @@ main() {
manage_plex_service stop
# Backup current data
local current_backup=$(backup_current_data)
if [ $? -ne 0 ]; then
local current_backup
if ! current_backup=$(backup_current_data); then
log_error "Failed to backup current data"
manage_plex_service start
exit 1