• 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 Development Feature Requests Jellyfin Backups & Migration

     
    • 2 Vote(s) - 5 Average

    Jellyfin Backups & Migration

    tim0502
    Offline

    Junior Member

    Posts: 2
    Threads: 1
    Joined: 2025 Mar
    Reputation: 0
    #7
    2025-03-06, 02:40 PM
    Hi guys,

    I've created a script that does a backup to a cloud location using rclone.
    with crontab you can automate it. I used it on Ubuntu Server.
    I run the script as root to need have any rights issues.

    #!/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
    1
    « Next Oldest | Next Newest »

    Users browsing this thread: 1 Guest(s)


    Messages In This Thread
    Jellyfin Backups & Migration - by LeviSnoot - 2023-09-19, 01:15 PM
    RE: Jellyfin Backups & Migration - by Fabri91 - 2023-09-22, 07:07 AM
    RE: Jellyfin Backups & Migration - by TheDreadPirate - 2023-09-22, 12:36 PM
    RE: Jellyfin Backups & Migration - by LeviSnoot - 2023-10-22, 07:45 PM
    RE: Jellyfin Backups & Migration - by enesha - 2025-03-08, 02:20 PM
    RE: Jellyfin Backups & Migration - by Marco2G - 2023-12-26, 09:54 AM
    RE: Jellyfin Backups & Migration - by cesar_bianchi - 2024-08-09, 07:10 PM
    RE: Jellyfin Backups & Migration - by tim0502 - 2025-03-06, 02:40 PM

    • 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