How to Transfer Plex Settings Between Servers

A Plex server doesn't last forever. Most people after using their Plex server for some time realize that they have outgrown their server. Perhaps they have used their day-to-day desktop and would like to use a dedicated system for their server.

If you have managed a Plex server for some time, you probably have changed multiple settings in Plex to suit your streaming needs.

When migrating your server to a new system, you would probably like to keep the same Plex settings you have used on your previous server.

This post outlines how you can use the Plex API, using a Python script, to transfer your Plex server settings from one system to another, even if the systems use different operating systems.

How to Transfer Plex Settings Between Servers

New server scenarios

If you are switching to a Plex server that has the same operating system as the original, you can easily copy over the settings from one server to the other.

Transferring settings does become more complicated when switching operating systems. The methods described in this post will work if the operating system remains the same, or a different operating system is to be used on the new server.

I will explore two different scenarios in this post: one where a new system will be used for Plex, and the second where the same system is used, such as changing the operating system.

The process of transferring the settings for each scenario is relatively similar. The one difference is how the settings from the original Plex server will be retrieved.

In the next two sections, I will provide Python scripts that will handle the transfer of settings from one Plex server to another.

The Python script will simply call one or two Plex API endpoints:

  1. Get Server Preferences
  2. Set a Server Preference

The first endpoint will get all the Plex settings from a server, while the second will change a setting on a Plex server.

With that in mind, let's have a look at the two scenarios.

A new server

In this scenario, you will be setting up a new system instead of modifying the existing server.

This is the better situation because if something goes wrong with the new server, you can fall back to the old server.

In this scenario, the steps you would take to transfer the settings between servers are as follows:

  1. Setup and claim the new server.
  2. Run the following script so it reads the settings from the old server, and then updates those settings on the new server.
  3. Restart Plex on the new server to ensure the new settings take effect.
  4. Verify that the new server is working correctly and all settings have been applied.

To transfer the settings to the new server, the following Python script can be used:

import requests
import xml.etree.ElementTree as ET

def get_plex_settings(ip_address, plex_token):
    """Retrieve Plex settings from the original server.
    
    Args:
        ip_address (str): IP address of the Plex server.
        plex_token (str): Authentication token for the Plex server.
    
    Returns:
        str: XML response containing Plex settings, or None if request fails.
    """
    url = f"http://{ip_address}:32400/:/prefs?X-Plex-Token={plex_token}"
    response = requests.get(url)
    
    if response.status_code != 200:
        print("Failed to fetch Plex settings.")
        return None
    
    return response.text

def parse_settings(xml_data):
    """Parse XML response and extract settings excluding specific ones.
    
    Args:
        xml_data (str): XML response from the Plex server.
    
    Returns:
        dict: Dictionary of settings with their respective values.
    """
    excluded_ids = {
        "ButlerDatabaseBackupPath", "FriendlyName", "LocalAppDataPath", 
        "MachineIdentifier", "PlexOnlineMail", "PlexOnlineToken", "PlexOnlineUrl", 
        "PlexOnlineUsername", "PlexWebAuthUrl", "PlexWebDesktopUrl", "ProcessedMachineIdentifier"
    }
    
    settings = {}
    root = ET.fromstring(xml_data)
    for setting in root.findall(".//Setting"):
        setting_id = setting.get("id")
        value = setting.get("value")
        default = setting.get("default")

        if value != default:
            if setting_id and setting_id not in excluded_ids:
                settings[setting_id] = value
    
    return settings

def update_plex_settings(ip_address, plex_token, settings):
    """Update settings on the new Plex server.
    
    Args:
        ip_address (str): IP address of the new Plex server.
        plex_token (str): Authentication token for the new Plex server.
        settings (dict): Dictionary of settings to be updated.
    """
    for name, value in settings.items():
        url = f"http://{ip_address}:32400/:/prefs?{name}={value}&X-Plex-Token={plex_token}"
        response = requests.put(url)
        
        if response.status_code == 200:
            print(f"Successfully updated {name} to {value}")
        else:
            print(f"Failed to update {name}")

def main():
    """Main function to fetch settings from the original Plex server and apply them to a new server."""
    # Define the original and new Plex server details
    original_ip_address = "ORIGINAL_PLEX_IP"
    new_ip_address = "NEW_PLEX_IP"
    original_plex_token = "ORIGINAL_PLEX_TOKEN"
    new_plex_token = "NEW_PLEX_TOKEN"
    
    # Fetch settings from the original Plex server
    xml_data = get_plex_settings(original_ip_address, original_plex_token)
    if xml_data:
        # Parse the settings, excluding certain ones
        settings = parse_settings(xml_data)
        # Apply settings to the new Plex server
        update_plex_settings(new_ip_address, new_plex_token, settings)

if __name__ == "__main__":
    main()

How to use the script

To use the script, you will need to do the following:

  1. Install Python.
  2. After Python is installed, run the following pip command to install the dependencies:
    pip install requests
  3. Copy the above script and save it as a Python file, for example, transfer_plex_settings.py
  4. Change the following lines to the IP addresses of the two servers and the Plex token for each server:
    original_ip_address = "ORIGINAL_PLEX_IP"
    new_ip_address = "NEW_PLEX_IP"
    original_plex_token = "ORIGINAL_PLEX_TOKEN"
    new_plex_token = "NEW_PLEX_TOKEN"
    

The above script will send a request to the Get Server Preferences endpoint on the old server to get all the settings.

The script will then loop through the settings, and send a request to the Set a Server Preference endpoint on the new server for each setting.

The same system

If you decide to reinstall Plex on the same system, then transferring settings between the Plex servers requires a different way of getting the server settings, since the original server will no longer be available.

So in this scenario, the steps would be:

  1. Send a request to the Get Server Preferences and save the response XML data to an XML file.
  2. Setup and claim the new server.
  3. Run the following script so it reads the settings from the XML file, and then updates those settings on the new server.
  4. Restart Plex on the new server to ensure the new settings take effect.
  5. Verify that the new server is working correctly and all settings have been applied.

The steps are similar to the previous scenario, except that the settings from the old server are first stored in a file that will be read by the script, instead of having the script send the request to get the settings.

The script below will read the settings from the file and apply them to the new server.

import requests
import xml.etree.ElementTree as ET

def read_xml_file(file_path):
    """Read XML data from a file.
    
    Args:
        file_path (str): Path to the XML file.
    
    Returns:
        str: XML content as a string.
    """
    with open(file_path, 'r', encoding='utf-8') as file:
        return file.read()

def parse_settings(xml_data):
    """Parse XML data and extract settings excluding specific ones.
    
    Args:
        xml_data (str): XML data as a string.
    
    Returns:
        dict: Dictionary of setting IDs and their corresponding values.
    """
    excluded_ids = {
        "ButlerDatabaseBackupPath", "FriendlyName", "LocalAppDataPath", 
        "MachineIdentifier", "PlexOnlineMail", "PlexOnlineToken", "PlexOnlineUrl", 
        "PlexOnlineUsername", "PlexWebAuthUrl", "PlexWebDesktopUrl", "ProcessedMachineIdentifier"
    }
    
    settings = {}
    root = ET.fromstring(xml_data)
    for setting in root.findall(".//Setting"):
        setting_id = setting.get("id")
        value = setting.get("value")
        default = setting.get("default")

        if value != default:
            if setting_id and setting_id not in excluded_ids:
                settings[setting_id] = value
    
    return settings

def update_plex_settings(ip_address, plex_token, settings):
    """Send a PUT request to update settings on the Plex server.
    
    Args:
        ip_address (str): IP address of the Plex server.
        plex_token (str): Authentication token for the Plex server.
        settings (dict): Dictionary of settings to update.
    """
    for name, value in settings.items():
        url = f"http://{ip_address}:32400/:/prefs?{name}={value}&X-Plex-Token={plex_token}"
        response = requests.put(url)
        
        if response.status_code == 200:
            print(f"Successfully updated {name} to {value}")
        else:
            print(f"Failed to update {name}")

def main():
    """Main function to read XML settings from a file and update them on a Plex server."""
    file_path = "plex_settings.xml"  # Path to the XML file
    ip_address = "YOUR_PLEX_SERVER_IP"
    plex_token = "YOUR_PLEX_TOKEN"
    
    xml_data = read_xml_file(file_path)
    if xml_data:
        settings = parse_settings(xml_data)
        update_plex_settings(ip_address, plex_token, settings)

if __name__ == "__main__":
    main()

How to use the script

To use the script, you will need to do the following:

  1. Install Python.
  2. After Python is installed, run the following pip command to install the dependencies:
    pip install requests
  3. Copy the above script and save it as a Python file, for example, transfer_plex_settings.py
  4. Change the following lines to the XML file path, and the IP address and token of the new server:
        file_path = "plex_settings.xml"  # Path to the XML file
        ip_address = "YOUR_PLEX_SERVER_IP"
        plex_token = "YOUR_PLEX_TOKEN"
    

The script will read the settings from the XML file that contains the original server's settings.

The script will then loop through the settings, and send a request to the Set a Server Preference endpoint on the new server for each setting.

This post has provided two scenarios for transferring settings from one Plex server to another, regardless of operating system. By utilizing the Plex API, you won't need to worry about how Plex stores its settings and can get back to just managing your server.

Photo of Paul Salmon
Started managing a Plex server in November 2014 and has been sharing his experience and what he has learned on Plexopedia. He is exploring and documenting the Plex API to help automate tasks for Plex to reduce the management effort of his server.
Subscribe
Display