• Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below
  • Forum
  • Website
  • GitHub
  • Status
  • Translation
  • Features
  • Team
  • Rules
  • Help
  • Feeds
User Links
  • Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below

    Useful Links Forum Website GitHub Status Translation Features Team Rules Help Feeds
    Jellyfin Forum Off Topic Self-hosting & Homelabs Automated backup solution

     
    • 0 Vote(s) - 0 Average

    Automated backup solution

    Automaticly backup to remote location using rclone
    tim0502
    Offline

    Junior Member

    Posts: 2
    Threads: 1
    Joined: 2025 Mar
    Reputation: 0
    #1
    2025-03-06, 02:48 PM
    When using the following script you can automaticly create a backup and upload it to a remote location using rclone.
    You need to have rclone configured before you can use this script.
    Before use you need to edit to script to be used with your system.

    #!/bin/bash

    # Variables
    BACKUP_DIRS=("/var/lib/jellyfin" "/etc/jellyfin")  # Directories to back up
    DEST_DIR="/mnt/data/backup-temp"  # Local temp storage for ZIPs
    ONEDRIVE_FOLDER="Backup/Jellyfin"  # Folder name in OneDrive
    MAX_BACKUPS=3  # Maximum number of backups to keep
    JELLYFIN_SERVICE="jellyfin"  # Jellyfin service name

    # Timestamp format YYYYMMDD_HHMMSS
    TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
    ZIP_FILE="$DEST_DIR/Jellyfin_backup_$TIMESTAMP.zip"

    # Ensure destination directory exists
    mkdir -p "$DEST_DIR"

    # Stop Jellyfin before backup
    echo "Stopping Jellyfin service..."
    sudo systemctl stop "$JELLYFIN_SERVICE"

    # Create a ZIP archive
    echo "Creating backup archive..."
    if zip -r "$ZIP_FILE" "${BACKUP_DIRS[@]}"; then
        echo "Backup created successfully: $ZIP_FILE"
    else
        echo "Backup creation failed!"
        sudo systemctl start "$JELLYFIN_SERVICE"
        exit 1
    fi

    # Start Jellyfin after backup
    echo "Starting Jellyfin service..."
    sudo systemctl start "$JELLYFIN_SERVICE"

    # Upload to OneDrive using rclone
    export RCLONE_CONFIG=/home/tim/.config/rclone/rclone.conf
    echo "Uploading backup to OneDrive..."
    if rclone copy "$ZIP_FILE" onedrive:"$ONEDRIVE_FOLDER" --progress; then
        echo "Upload successful."
        rm "$ZIP_FILE"  # Remove local ZIP after upload
    else
        echo "Upload failed!"
        exit 1
    fi

    # Delete oldest backups if more than $MAX_BACKUPS exist
    echo "Checking for old backups to delete..."
    BACKUPS_ON_ONEDRIVE=$(rclone lsf onedrive:"$ONEDRIVE_FOLDER" | sort | head -n -$MAX_BACKUPS)

    for FILE in $BACKUPS_ON_ONEDRIVE; do
        echo "Deleting old backup: $FILE"
        rclone delete onedrive:"$ONEDRIVE_FOLDER/$FILE"
    done
    « Next Oldest | Next Newest »

    Users browsing this thread: 1 Guest(s)


    • View a Printable Version
    • Subscribe to this thread
    Forum Jump:

    Home · Team · Help · Contact
    © Designed by D&D - Powered by MyBB
    L


    Jellyfin

    The Free Software Media System

    Linear Mode
    Threaded Mode