Carl Swart

My feedback

  1. 207 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    29 comments  ·  Feature Suggestions » Plesk (general)  ·  Flag idea as inappropriate…  ·  Admin →
    Carl Swart commented  · 

    A few pointers after having to do it for the umpteenth time. :)

    All needs to be done via SSH on the command line interface.

    # /usr/local/psa/bin/service_plan --xml-info 'SERVICE_PLAN_NAME' >> service_plans.xml

    Dump all your service plans into a service_plans.xml file using the --xml-info command of the service_plan tool supplied by Plesk.

    Then use my code below on the new server to import the service plans from the service_plans.xml file.

    There are differences in the service_plan tool parameters in the different versions of Plesk so, study the 3 arrays, $convert, $deprecated, $sizes and adjust as needed.

    # cat make_service_plans.php
    <?php

    // Enable for debug output
    define('DEBUG', 1);

    $file = 'service_plans.xml';

    $xml = new DOMDocument();
    $xml->loadXML('<service_plans>'.file_get_contents($file).'</service_plans>');

    $convert = array('wu_script' => 'wuscripts', 'nonexist_mail' => 'no_usr', 'errdocs' => 'err_docs', 'pdir_plesk_stat' => 'webstat_protdir', 'stat_ttl' => 'keep_traf_stat');
    $deprecated = array('fp', 'fp_ssl', 'fp_auth', 'php_handler_type', 'php_safe_mode', 'dns_type', 'same_ssl', 'allow_license_stubs');
    $sizes = ['disk_space', 'quota', 'mbox_quota'];

    $service_plans = $xml->getElementsByTagName('domain-service-plan');

    foreach($service_plans as $service_plan) {
    $command = '/usr/local/psa/bin/service_plan ';
    $service_plan_name = $service_plan->getAttribute('name');
    $service_plan_owner = $service_plan->getAttribute('owner-login');
    // echo "$service_plan_name - Owned by: $service_plan_owner\n";
    $command .= "--create '$service_plan_name' ";
    if ($service_plan_owner != "admin") {
    $command .= "-owner $service_plan_owner ";
    }

    foreach($service_plan->getElementsByTagName('service-plan-item') as $service_plan_item) {
    $name = $service_plan_item->getAttribute('name');
    $value = $service_plan_item->nodeValue;
    if (($name == 'vh_type') && ($value == 'physical')) {
    $name = 'hosting';
    $value = 'true';
    }
    // Remove deprecated settings
    if (in_array($name, $deprecated)) {
    continue;
    }
    // Convert old settings
    if (in_array($name, array_keys($convert))) {
    $name = $convert[$name];
    }
    // Convert bytes to MB
    if (in_array($name, $sizes)) {
    $value = $value / 1024 / 1024;
    $value .= 'M';
    }
    $command .= "-$name $value ";
    }

    $final_command = trim($command);
    $command_result = `$final_command`;
    if (!preg_match("/(SUCCESS: | successfully )/", $command_result)) {
    print("ERROR: $command_result - $final_command\n");
    }
    }

    ?>

    Run the script: #php make_service_plans.php

    Hope it helps somebody.

Feedback and Knowledge Base