Skip to content
www.mytechnote.ru
Menu
  • Administration
    • Scripts
  • Equipment
    • Reviews
    • Instructions
  • Other
  • English
    • English
    • Русский
Menu

WebSitePanel. How to migrate hosting spaces to the other server

Hello. I was asked to migrate hosting spaces of websitepanel hosting panel to the other server, so that new and old hosting plans would work on the new server. After transferring resources to the new server, you need to update the websitepanel database, otherwise it will continue to use the old servers. This can be done using a TSQL script.

First, we declare all the variables we need:

 --In the <span id="result_box" lang="en"><span>wsp there should not to be duplicate server names and virtual servers names.</span></span>
use websitepanel;
declare @user varchar(60);
declare @virt_server_name varchar(60);
declare @old_virt_server_name varchar(60);
declare @server_name varchar(60);
declare @old_server_name varchar(60);
declare @service_name varchar(60);
declare @old_service_name varchar(60);
declare @package_name varchar(60);

set @user='username'; --<span class="short_text" id="result_box" lang="en"><span>Username for which we change hosting space</span></span>
set @virt_server_name=''; --<span class="short_text" id="result_box" lang="en"><span>The name of the new virtual server, if it changes</span></span>
set @old_virt_server_name=''; --<span id="result_box" lang="en"><span>The name of the old virtual server, if it is changing</span></span>
set @server_name='SrvHost2012'; --<span class="short_text" id="result_box" lang="en"><span>The name of the new server</span></span>
set @old_server_name='SrvHOST2008'; --The name of the old server

set @service_name='IIS 2012'; --<span class="short_text" id="result_box" lang="en"><span>Name of new service</span></span>
set @old_service_name='IIS 2008'; --<span class="short_text" id="result_box" lang="en"><span>Old service name</span></span>

set @package_name='hosting plan'; --Hostin plan name

declare @user_id int;
declare @server_id int;
declare @package_id int;
declare @service_id int
declare @old_server_id int;
declare @old_service_id int;
declare @virt_server_id int;
declare @old_virt_server_id int;

declare @err int;
declare @rc int;

--<span id="result_box" lang="en"><span>Below, variables are assigned an ID, depending on the names.</span></span> 
--<span id="result_box" lang="en"><span>If you do not use English characters anywhere, you must manually add names below this block</span></span>
select @user_id = UserID from Users where Username=@user;
select @old_server_id = Servers.ServerID from Servers where Servers.ServerName=@old_server_name;
select @server_id = Servers.ServerID from Servers where Servers.ServerName=@server_name;
select @virt_server_id = Servers.ServerID from Servers where Servers.ServerName=@virt_server_name;
select @old_virt_server_id = Servers.ServerID from Servers where Servers.ServerName=@virt_server_name;
select @package_id = Packages.PackageID from Packages where (Packages.UserID=@user_id and Packages.PackageName=@package_name);
select @old_service_id = Services.ServiceID from Services where services.ServiceName=@old_service_name and Services.ServerID=@old_server_id;
select @service_id = Services.ServiceID from Services where services.ServiceName=@service_name and Services.ServerID=@server_id;

Thats all with declaration of variables. 2 sets of commands will be shown below. 1 should be used if you are going to transfer hosting space for one user, the second changes the values for all users and all hosting plans

1)

-- <span class="short_text" id="result_box" lang="en"><span>To update bindings for one client</span></span>
BEGIN TRANSACTION t1;

-- <span id="result_box" lang="en"><span>Update the server binding in the hosting plan if the virtual server is changing.</span></span>
          update Packages set ServerID=@virt_server_id where (Packages.UserID=@user_id and Packages.PackageName=@package_name);
          IF (@err <> 0)
          BEGIN
                 ROLLBACK TRANSACTION t1;
                 RAISERROR ('', 16, 1);
          END

-- <span id="result_box" lang="en"><span>Update the hosting of the space, that it would refer to the new service.</span></span>
          update PackageServices set ServiceID=@service_id where (PackageID=@package_id and ServiceID=@old_service_id);
          SELECT @rc = @@ROWCOUNT, @err = @@ERROR;
          IF (@err <> 0)
          BEGIN
                ROLLBACK TRANSACTION t1;
                RAISERROR ('ACHTUNG!!!', 16, 1);
          END
            
-- <span id="result_box" lang="en"><span>Update hosting space, that would be the existing service worked on a new server</span></span>
          update ServiceItems set ServiceID=@service_id where ServiceID=@old_service_id and PackageID=@package_id
          IF (@err <> 0)
          BEGIN
                    ROLLBACK TRANSACTION t1;
                    RAISERROR ('ACHTUNG!!!', 16, 1);
          END
--    
    
 COMMIT TRANSACTION t1;

2)

-- <span class="short_text" id="result_box" lang="en"><span>To update the services for all clients:</span></span>
BEGIN TRANSACTION t1;
-- <span id="result_box" lang="en"><span>Updating bindings on a virtual server to the server</span></span>
       update VirtualServices set ServiceID=@service_id where (ServerID=@virt_server_id and ServiceID=@old_service_id)
       IF (@err <> 0)
       BEGIN
                 ROLLBACK TRANSACTION t1;
                 RAISERROR ('<span class="short_text" id="result_box" lang="en"><span>Error in updating virtual services</span></span>', 16, 1);
       END
        
-- <span id="result_box" lang="en"><span>Update bindings on all virtual servers to the server</span></span>
       update VirtualServices set ServiceID=@service_id where (ServiceID=@old_service_id)
       IF (@err <> 0)
       BEGIN
                 ROLLBACK TRANSACTION t1;
                 RAISERROR ('<span class="short_text" id="result_box" lang="en"><span>Error in updating virtual services</span></span>', 16, 1);
       END
        
-- <span class="short_text" id="result_box" lang="en"><span>Update server bindings for all hosting plans</span></span>
        update Packages set ServerID=@virt_server_id where ServerID=@old_virt_server_id;
        IF (@err <> 0)
        BEGIN
                  ROLLBACK TRANSACTION t1;
                  RAISERROR ('<span class="short_text" id="result_box" lang="en"><span>Error in updating hosting plans</span></span>', 16, 1);
        END

-- <span id="result_box" lang="en"><span>Update all hosting spaces, that they would refer to a new service.</span></span>
        update PackageServices set ServiceID=@service_id where (ServiceID=@old_service_id);
        IF (@err <> 0)
        BEGIN
                  ROLLBACK TRANSACTION t1;
                  RAISERROR ('<span class="short_text" id="result_box" lang="en"><span>Error in updating the service</span></span>', 16, 1);
        END

-- <span id="result_box" lang="en"><span>Update hosting space, that would be the existing service worked on a new server</span></span>
        update ServiceItems set ServiceID=@service_id where ServiceID=@old_service_id
        IF (@err <> 0)
        BEGIN
                  ROLLBACK TRANSACTION t1;
                  RAISERROR ('<span class="short_text" id="result_box" lang="en"><span>Error in updating the service items</span></span>', 16, 1);
        END
 
    COMMIT TRANSACTION t1;

I recommend that you make backups before every application of the script, and after each application check the work of the changed hosting plan.

Posted on 31.07.201730.05.2024 by sanglyb

Post navigation

← How to Reset Root Password in CentOS 6 and CentOS 7: A Step-by-Step Guide
How to record video from the screen in Ubuntu →

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Подписывайтесь

Youtube
vk
telegram
github
twitter
rss
  • Форум
  • Об авторе
  • Поддержать автора

Популярные записи

Новые записи

  • How to Extend an LVM Partition in Linux
  • SCCM Reporting Errors After Migrating from SQL Server 2016 to 2019
  • Problem Using PassFiltEx on Older CPUs
  • How to remove attachments from old calendar events in Exchange using a script
  • How to download and install Office 2024 LTSC

Архивы

  • 2026 (3)
  • 2025 (5)
  • 2024 (7)
  • 2023 (30)
  • 2022 (4)
  • 2020 (17)
  • 2017 (82)
  • 2016 (5)
© 2015-2026 www.mytechnote.ru
Использование материалов сайта возможно только с разрешения владельца или обязательна индексируемая, прямая, передающая вес ссылка на материал.