🎬 ARR Suite Template Bootstrap - Complete Media Automation Stack Features: - 16 production services (Prowlarr, Sonarr, Radarr, Plex, etc.) - One-command Ansible deployment - VPN-protected downloads via Gluetun - Tailscale secure access - Production-ready security (UFW, Fail2Ban) - Automated backups and monitoring - Comprehensive documentation Ready for customization and deployment to any VPS. Co-authored-by: openhands <openhands@all-hands.dev>
221 lines
5.7 KiB
Bash
Executable File
221 lines
5.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Synology Arrs Stack Backup Script
|
|
# This script creates backups of your Arrs configurations
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Function to print colored output
|
|
print_status() {
|
|
echo -e "${GREEN}[INFO]${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
# Load environment variables
|
|
load_env() {
|
|
if [ -f ".env" ]; then
|
|
set -a
|
|
source .env
|
|
set +a
|
|
print_status "Environment loaded from .env"
|
|
else
|
|
print_warning ".env file not found, using defaults"
|
|
CONFIG_ROOT="/volume1/docker"
|
|
fi
|
|
}
|
|
|
|
# Create backup
|
|
create_backup() {
|
|
local backup_date=$(date +"%Y%m%d_%H%M%S")
|
|
local backup_dir="backups/arrs_backup_$backup_date"
|
|
|
|
print_status "Creating backup directory: $backup_dir"
|
|
mkdir -p "$backup_dir"
|
|
|
|
# Backup each service configuration
|
|
local services=("sonarr" "radarr" "lidarr" "bazarr" "prowlarr")
|
|
|
|
for service in "${services[@]}"; do
|
|
local config_path="$CONFIG_ROOT/$service"
|
|
if [ -d "$config_path" ]; then
|
|
print_status "Backing up $service configuration..."
|
|
cp -r "$config_path" "$backup_dir/"
|
|
else
|
|
print_warning "$service configuration directory not found: $config_path"
|
|
fi
|
|
done
|
|
|
|
# Backup environment file
|
|
if [ -f ".env" ]; then
|
|
print_status "Backing up .env file..."
|
|
cp ".env" "$backup_dir/"
|
|
fi
|
|
|
|
# Backup docker-compose files
|
|
if [ -d "compose" ]; then
|
|
print_status "Backing up compose files..."
|
|
cp -r "compose" "$backup_dir/"
|
|
fi
|
|
|
|
# Create archive
|
|
print_status "Creating compressed archive..."
|
|
tar -czf "arrs_backup_$backup_date.tar.gz" -C backups "arrs_backup_$backup_date"
|
|
|
|
# Remove uncompressed backup
|
|
rm -rf "$backup_dir"
|
|
|
|
print_status "Backup created: arrs_backup_$backup_date.tar.gz"
|
|
|
|
# Show backup size
|
|
local backup_size=$(du -h "arrs_backup_$backup_date.tar.gz" | cut -f1)
|
|
print_status "Backup size: $backup_size"
|
|
}
|
|
|
|
# Restore backup
|
|
restore_backup() {
|
|
local backup_file="$1"
|
|
|
|
if [ -z "$backup_file" ]; then
|
|
print_error "Please specify a backup file to restore"
|
|
echo "Usage: $0 restore <backup_file.tar.gz>"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "$backup_file" ]; then
|
|
print_error "Backup file not found: $backup_file"
|
|
exit 1
|
|
fi
|
|
|
|
print_warning "This will overwrite existing configurations!"
|
|
read -p "Are you sure you want to continue? (y/N): " -n 1 -r
|
|
echo
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
print_status "Restore cancelled"
|
|
exit 0
|
|
fi
|
|
|
|
# Extract backup
|
|
local temp_dir="temp_restore_$(date +%s)"
|
|
mkdir -p "$temp_dir"
|
|
|
|
print_status "Extracting backup..."
|
|
tar -xzf "$backup_file" -C "$temp_dir"
|
|
|
|
# Find the backup directory
|
|
local backup_dir=$(find "$temp_dir" -name "arrs_backup_*" -type d | head -n1)
|
|
|
|
if [ -z "$backup_dir" ]; then
|
|
print_error "Invalid backup file structure"
|
|
rm -rf "$temp_dir"
|
|
exit 1
|
|
fi
|
|
|
|
# Restore configurations
|
|
local services=("sonarr" "radarr" "lidarr" "bazarr" "prowlarr")
|
|
|
|
for service in "${services[@]}"; do
|
|
if [ -d "$backup_dir/$service" ]; then
|
|
print_status "Restoring $service configuration..."
|
|
rm -rf "$CONFIG_ROOT/$service"
|
|
cp -r "$backup_dir/$service" "$CONFIG_ROOT/"
|
|
fi
|
|
done
|
|
|
|
# Restore .env file
|
|
if [ -f "$backup_dir/.env" ]; then
|
|
print_status "Restoring .env file..."
|
|
cp "$backup_dir/.env" "./"
|
|
fi
|
|
|
|
# Clean up
|
|
rm -rf "$temp_dir"
|
|
|
|
print_status "Restore completed successfully!"
|
|
print_warning "You may need to restart the containers for changes to take effect"
|
|
}
|
|
|
|
# List backups
|
|
list_backups() {
|
|
print_status "Available backups:"
|
|
echo ""
|
|
|
|
if ls arrs_backup_*.tar.gz 1> /dev/null 2>&1; then
|
|
for backup in arrs_backup_*.tar.gz; do
|
|
local size=$(du -h "$backup" | cut -f1)
|
|
local date=$(echo "$backup" | sed 's/arrs_backup_\([0-9]\{8\}_[0-9]\{6\}\).tar.gz/\1/' | sed 's/_/ /')
|
|
echo -e "${BLUE}$backup${NC} - Size: $size - Date: $date"
|
|
done
|
|
else
|
|
print_warning "No backups found"
|
|
fi
|
|
echo ""
|
|
}
|
|
|
|
# Clean old backups
|
|
clean_backups() {
|
|
local keep_days=${1:-30}
|
|
|
|
print_status "Cleaning backups older than $keep_days days..."
|
|
|
|
find . -name "arrs_backup_*.tar.gz" -mtime +$keep_days -delete
|
|
|
|
print_status "Old backups cleaned"
|
|
}
|
|
|
|
# Main execution
|
|
main() {
|
|
echo -e "${BLUE}=== Synology Arrs Stack Backup Tool ===${NC}"
|
|
echo ""
|
|
|
|
# Create backups directory
|
|
mkdir -p backups
|
|
|
|
load_env
|
|
|
|
case "${1:-backup}" in
|
|
"backup"|"create")
|
|
create_backup
|
|
;;
|
|
"restore")
|
|
restore_backup "$2"
|
|
;;
|
|
"list")
|
|
list_backups
|
|
;;
|
|
"clean")
|
|
clean_backups "$2"
|
|
;;
|
|
"help"|"-h"|"--help")
|
|
echo "Usage: $0 [command] [options]"
|
|
echo ""
|
|
echo "Commands:"
|
|
echo " backup, create Create a new backup (default)"
|
|
echo " restore <file> Restore from backup file"
|
|
echo " list List available backups"
|
|
echo " clean [days] Clean backups older than X days (default: 30)"
|
|
echo " help Show this help"
|
|
;;
|
|
*)
|
|
print_error "Unknown command: $1"
|
|
echo "Use '$0 help' for usage information"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Run main function
|
|
main "$@" |