Skip to content

Instantly share code, notes, and snippets.

@b13n1u
Last active February 13, 2018 17:45
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save b13n1u/11094749 to your computer and use it in GitHub Desktop.
Save b13n1u/11094749 to your computer and use it in GitHub Desktop.
I-MSCP migration from old server to a new one.
#Migrate i-mscp to a new server
#the new imscp is already installed and does have a different IP than the old one
#1. Dump the DB and copy the i-MSCP backup to new server:
rsync -rave "ssh -l root" /var/www/imscp/backups 10.0.0.3:/var/tmp/imscp_old_backups
#2.Install the old config DB
#3. Copy all customer data:
rsync -rave "ssh -l root " /var/www/virtual/ 10.0.0.3:/var/www/virtual
rsync -rave "ssh -l root " /var/mail/virtual/ 10.0.0.3:/var/mail/virtual
#4. Copy all cusomer DB's
(use phpmyadmin or mysqldump to move customers db's)
#5. Remove all unix user related fields into the admin table before re-running the installer (on new server)
#- Edit your /etc/passwd file and remove any vuXXXX user
#- Edit your /etc/group file and remove any vuXXXX group
#- Edit your /etc/shadow file and remove any vuXXXX user
#Execute the following SQL queries:
# mysql -u root -p<password>
use imscp; #your imscp config
update domain set domain_status = 'ok';
update subdomain set subdomain_status = 'ok';
update domain_aliasses set alias_status = 'ok';
update subdomain_alias set subdomain_alias_status = 'ok';
update mail_users set status = 'ok';
update admin set admin_status = 'ok', admin_sys_name = null, admin_sys_uid = 0, admin_sys_gname = null, admin_sys_gid = 0;
#5. Run again the setup script:
perl /var/www/imscp/engine/setup/imscp-setup -d
#6. If you need to change the default IP address run:
perl /var/www/imscp/engine/setup/imscp-setup --reconfigure ips
#if it happens that you can not delete the old IP address, check the IP's used by reseller.
# Anything else ?????
Copy link

ghost commented Oct 30, 2014

Thanks <3

@explanar
Copy link

explanar commented Feb 1, 2015

Here's what we made out of your howto, but be careful - it is an experimental script:

# explanar.de semi-automatical imscp migration and movement script
# reference: https://gist.github.com/b13n1u/11094749


#################### Has to be divided into 2 different .sh-files for old and new server !!! ###########################






##################### THIS IS SCRIPT 1 FOR THE OLD SERVER #########################
clear
echo "explanar.de semi-automatical imscp migration and movement script"
echo "---------------------------[ PART 1 ]---------------------------"
echo "reference: https://gist.github.com/b13n1u/11094749"
read -p "ready ? [ENTER]" nothing
clear
read -p "Please enter MySQL Root-Password: " mysqlroot

username=$(who -m | awk '{print $1;}')
sudo mkdir -p /var/www/BACKUP/
sudo chown -R "$username":"$username" /var/www/BACKUP
sudo tar cvpzf /var/www/BACKUP/var-www-imscp-backups.tar.gz /var/www/imscp/backups/*
sudo tar cvpzf /var/www/BACKUP/var-www-virtual.tar.gz /var/www/virtual/*
sudo tar cvpzf /var/www/BACKUP/var-mail-virtual.tar.gz /var/mail/virtual/*
sudo tar --exclude='*.pid' cvpzf /var/www/BACKUP/var-lib-mysql.tar.gz /var/lib/mysql/*
# for security and redundancy: additional mysqldump backup
sudo mysqldump -p --all-databases -u root --password=$mysqlroot > /var/www/BACKUP/mysqldump2.sql


echo "Please download all .tar.gz-Backup-Archives from /var/www/BACKUP !"
echo "You can use e.g. filezilla to connect via ssh."
read -p "ready ? [ENTER]" nothing
exit 0


##################### THIS IS SCRIPT 2 FOR THE NEW SERVER (Ubuntu 14.04 Minimal) #########################


clear
echo "explanar.de semi-automatical imscp migration and movement script"
echo "---------------------------[ PART 2 ]---------------------------"
echo "reference: https://gist.github.com/b13n1u/11094749"
read -p "ready ? [ENTER]" nothing
username=$(who -m | awk '{print $1;}')
sudo mkdir -p /var/www/BACKUP
sudo chown -R "$username":"$username" /var/www/BACKUP
clear
echo "Please upload all .tar.gz-Backup-Archives to /var/www/BACKUP !"
echo "You can use e.g. filezilla to connect via ssh."
read -p "ready ? [ENTER]" nothing
clear
read -p "Please enter Hostname:" newhostname
sudo su -c 'echo '$newhostname' > /etc/hostname'
sudo hostname -F /etc/hostname
clear
read -p "Please the enter MySQL Root-Password you will use: " mysqlroot

# Installation neues System
sudo apt-get update && sudo apt-get upgrade
sudo apt-get -y install whiptail tasksel
sudo tasksel install standard
cd /usr/local/src 
sudo rm -fR imscp*
sudo wget https://github.com/i-MSCP/imscp/archive/1.2.0.tar.gz 
sudo tar xzf 1.2.0.tar.gz
cd imscp-1.2.0
echo "If this is a local install, please change the file"
echo ""
echo "/usr/local/src/imscp-1.2.0/engine/setup/imscp-setup-methods.pl"
echo ""
echo "from"
echo "(domain_private_tld => qr /^(?:bogus|test)$/)"
echo ""
echo "to"
echo "(domain_private_tld => qr /^(?:bogus|test|lan)$/)"
echo ""
echo "else just hit enter"
echo ""
read -p "ready ? [ENTER]" nothing
sudo perl imscp-autoinstall -d

sudo mkdir -p /var/www/BACKUP-NEW/
sudo chown -R "$username":"$username" /var/www/BACKUP-NEW
sudo tar cvpzf /var/www/BACKUP-NEW/var-lib-mysql.tar.gz /var/lib/mysql/*
sudo tar cvpzf /var/www/BACKUP-NEW/var-www-virtual.tar.gz /var/www/virtual/*
sudo tar cvpzf /var/www/BACKUP-NEW/var-mail-virtual.tar.gz /var/mail/virtual/*
sudo rm -rf /var/www/virtual/* /var/mail/virtual/*
find /var/lib/mysql -type f ! -name '*.pid' -execdir rm -rf {} +

clear
echo "If all uploads of .tar.gz-Backup-Archives to /var/www/BACKUP"
read -p "are ready, please [ENTER]" nothing
sudo tar xpvzf /var/www/BACKUP/var-www-imscp-backups.tar.gz -C /var/www/imscp/backups/
sudo tar xpvzf /var/www/BACKUP/var-www-virtual.tar.gz -C /var/www/virtual/
sudo tar xpvzf /var/www/BACKUP/var-mail-virtual.tar.gz -C /var/mail/virtual/
sudo tar xpvzf /var/www/BACKUP/var-lib-mysql.tar.gz -C /var/lib/mysql/


# delete all newly installed vu****-user
sudo sed '/vu/d' /etc/shadow
sudo sed '/vu/d' /etc/group
sudo sed '/vu/d' /etc/passwd

# MySQL Befehle
mysql -u root -p $mysqlroot -h localhost <update.sql

perl /var/www/imscp/engine/setup/imscp-setup -d 

echo "Is the IP-Address of this server the same as the one of the old server?"
select yn in "Yes" "No"
case $yn in
    Yes ) exit;;
    No ) perl /var/www/imscp/engine/setup/imscp-setup --reconfigure ips;;
esac

@ciscllc
Copy link

ciscllc commented Feb 2, 2016

Thank you. Will try. Would be nice to have a rsync doing the copying between the servers.

@theemstra
Copy link

theemstra commented May 10, 2016

From 1.3.x this script will no longer function, because you can not longer use the mysql root.
A seperate user is created, so this script will have to be altered, by using mysqldump -u imscp_user -p $pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment