Skip to content

Instantly share code, notes, and snippets.

@yorch
Created March 7, 2014 12:39
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 20 You must be signed in to fork a gist
  • Save yorch/9410737 to your computer and use it in GitHub Desktop.
Save yorch/9410737 to your computer and use it in GitHub Desktop.
ISPConfig 3 script to move installation from one server to another
#!/bin/bash
# Migrate ISPConfig 3 installation from one server to another
# This script should run on the final/destination ISPConfig 3 server
# You must first install the same ISPConfig on the destination server
# and make sure to create all the users from the previous installation
# (ISPConfig creates users for each client and web page)
# Tested on ISPConfig version 3.0.5.3
# Created by Jorge Barnaby (@jbarnaby) - March 2014
# EDIT YOUR PREVIOUS ISPCONFIG SERVER HERE
main_server=old-server.domain.com
#common_args='-aPv --delete'
#common_args='-aPv --dry-run'
common_args='-aPv'
www_start="service apache2 start"
www_stop="service apache2 stop"
db_start="service mysql start"
db_stop="service mysql stop"
function db_migration {
echo "---- Starting DB migration..."
# Stop Remote and Local MySQL Servers
ssh $main_server "$db_stop"
$db_stop
# Copy MySQL files
rsync $common_args --compress --delete $main_server:/var/lib/mysql/ /var/lib/mysql
# Start Remote and Local MySQL Servers
ssh $main_server "$db_start"
$db_start
# TODO:
# You should update ISPConfig MySQL Password to match your new server's, as it's stored in
# several ISPConfig files (it's a faster approach than updating the password in all those places)
# Enter MySQL on the destination server and run:
# SET PASSWORD FOR 'ispconfig'@'localhost' = PASSWORD('YOUR NEW ISPCONFIG MYSQL PASSWORD');
# You should also make shure all the tables on the destination server are clean:
# mysqlcheck -A --auto-repair
echo "---- DB migration done."
}
function www_migration {
echo "---- Starting WWW migration..."
$www_stop
rsync $common_args --compress --delete $main_server:/var/www/ /var/www
rsync $common_args --compress --delete $main_server:/var/log/ispconfig/httpd/ /var/log/ispconfig/httpd
$www_start
echo "---- WWW migration done."
}
function mail_migration {
echo "---- Starting Mail migration..."
rsync $common_args --compress --delete $main_server:/var/vmail/ /var/vmail
rsync $common_args --compress --delete $main_server:/var/log/mail.* /var/log/
echo "---- Mail migration done."
}
function files_migration {
echo "---- Starting Files migration..."
rsync $common_args $main_server:/var/backup/ /var/backup
# The following files are copied just to have a reference of the previous
# installation users and groups. You should manually create those users in
# your new server
rsync $common_args $main_server:/etc/passwd /root/old-server/
rsync $common_args $main_server:/etc/group /root/old-server/
echo "---- Files migration done."
}
function mailman_migration {
echo "Starting MailMan Migration..."
rsync $common_args --compress --delete $main_server:/var/lib/mailman/lists /var/lib/mailman
rsync $common_args --compress --delete $main_server:/var/lib/mailman/data /var/lib/mailman
rsync $common_args --compress --delete $main_server:/var/lib/mailman/archives /var/lib/mailman
# Update / Regenerate aliases
cd /var/lib/mailman/bin && ./genaliases
echo "MailMan Migration done."
}
# Execute migrations
www_migration
mail_migration
db_migration
files_migration
mailman_migration
@redb
Copy link

redb commented Oct 3, 2015

nice. Except i cant connect to my admin ispconfig !!!! :-(

@olimortimer
Copy link

FYI this doesn't copy across things like /etc/apache2/sites-available and /etc/apache2/sites-enabled, so although web files and dirs have been copied, the sites won't work as Apache doesn't know about them.

@shoaibali
Copy link

Source: https://raw.githubusercontent.com/teris/Debian-ISPConfig3-migration/master/migration.sh

#!/bin/bash
#
  echo "############################################################"
  echo "##                   Herzlich Willkommen                  ##"
  echo "##   Bitte beachten Sie alle Hinweise und Empfehlungen    ##"
  echo "##                                                        ##"
  echo "##   Bei Fragen oder Problemen können Sie jederzeit       ##"
  echo "##   unter http://wiki.teris-cooper.de nachlesen          ##"
  echo "##                                                        ##"
  echo "##  Gern können Sie auch eine E-Mail senden an:           ##"
  echo "##  admin [at] teris-cooper [dot] de                      ##"
  echo "############################################################"
  echo ""
  echo "Bitte geben Sie zunächst die Serveradresse Ihres Master Server ein:"
  read main_server


#common_args='-aPv --delete'
#common_args='-aPv --dry-run'
common_args='-aPv'
install_rsync="apt-get -y install rsync"
www_start="service apache2 start"
www_stop="service apache2 stop"
db_start="service mysql start"
db_stop="service mysql stop"

function menu {
    clear
    echo "############################################################"
    echo "##                    Hauptmenu                           ##"
    echo "##                                                        ##"
    echo "##Installation von RSync auf dem Remote Server starten (1)##"
    echo "##MySql Syncronisation starten                         (2)##"
    echo "##Webverzeichnis Syncronisation starten                (3)##"
    echo "##E-Mail Syncronisation starten                        (4)##"
    echo "##Passwörter und Benutzerkonten Syncronisation starten (5)##"
    echo "##MailMan Syncronisation starten                       (6)##"
    echo "##Programm beenden                                     (0)##"
    echo "############################################################"
    read -n 1 eingabe
}

function install {
    clear
    echo "Installation von Rsync auf dem Remote Server..."
    ssh $main_server "$install_rsync"
    echo "Ending"
    menu
}

function db_migration {
    clear
  echo "############################################################"
  echo "############################################################"
  echo "##############Starte MySql Migration           #############"
  echo "##############Step1:                           #############"
  echo "##############Erstelle Backup auf Remot Server #############"
  echo "############################################################"
  echo "##############Step2:                           #############"
  echo "##############MySql Datenbank Kopieren         #############"
  echo "############################################################"
  echo "#############Step3:                            #############"
  echo "#############MySql Datenabnk einspielen        #############"
  echo "############################################################"
  echo "############################################################"
  echo " "
  echo "Erstelle Datenbank Backup................................................................"
  echo "Bitte geben Sie das MySql-Passwort für den Benutzer ROOT auf dem Server $main_server ein:"
  read mysqlext
  ssh $main_server "mysqldump -u root -p$mysqlext --all-databases > fulldump.sql"
  clear
  echo "Kopieren des Backups....................................................................."
  rsync $common_args $main_server:/root/mysql/ /root/mysql/
  clear
  echo "Backup einspielen........................................................................"
  echo "Bitte geben Sie das MySql-Passwort für den Benuter ROOT ein:............................."
  read mysql2
  mysql -u root -p$mysql2 < /root/mysql/fulldump.sql
  clear
  echo "Führe MySql Check durch.................................................................."
  mysqlcheck -p -A --auto-repair
  echo "############################################################"
  echo "############################################################"
  menu
}

function www_migration {
    clear

  echo "############################################################"
  echo "############################################################"
  echo "##################Starte Web Migartion######################"
  echo "##################Step1:                  ##################"
  echo "##################Stoppen des Webservers  ##################"
  echo "############################################################"
  echo "##################Step2:                  ##################"
  echo "##################Migartion Starten       ##################"
  echo "############################################################"
  $www_stop
  rsync $common_args --compress --delete $main_server:/var/www/ /var/www
  rsync $common_args --compress --delete $main_server:/var/log/ispconfig/httpd/ /var/log/ispconfig/httpd
  $www_start
  echo "############################################################"
  echo "############################################################"
  menu
}

function mail_migration {
    clear
  echo "---- Starting Mail migration..."
  echo "############################################################"
  echo "############################################################"
  echo "##################Starte Mail Migartion   ##################"
  echo "##################Step1:                  ##################"
  echo "##################Migration vmail         ##################"
  echo "############################################################"
  echo "##################Step2:                  ##################"
  echo "##################Migartion vmail Logs    ##################"
  echo "############################################################"
  rsync $common_args --compress --delete $main_server:/var/vmail/ /var/vmail
  rsync $common_args --compress --delete $main_server:/var/log/mail.* /var/log/
  echo "############################################################"
  echo "############################################################"
  menu
}

function files_migration {
    clear
  echo "############################################################"
  echo "############################################################"
  echo "#############Starte Benutzer und Gruppen migration   #######"
  echo "#############Step1:                                  #######"
  echo "#############Kopiere Backup                          #######"
  echo "############################################################"
  echo "#############Step2:                                  #######"
  echo "#############Kopiere Passwd in /root/old-server      #######"
  echo "############################################################"
  echo "#############Step3:                                  #######"
  echo "#############Kopiere group in /root/old-server       #######"
  echo "############################################################"
  echo "#############Bitte Manuel migriren                   #######"
  echo "#############mehr auf http://wiki.teris-cooper.de    #######"
  echo "############################################################"
  rsync $common_args $main_server:/var/backup/ /var/backup
  rsync $common_args $main_server:/etc/passwd /root/old-server/
  rsync $common_args $main_server:/etc/group  /root/old-server/
  echo "############################################################"
  echo "############################################################"
  menu
}

function mailman_migration {
    clear
  echo "############################################################"
  echo "############################################################"
  echo "############Starte Mailman migration           #############"
  echo "############################################################"
  rsync $common_args --compress --delete $main_server:/var/lib/mailman/lists /var/lib/mailman
  rsync $common_args --compress --delete $main_server:/var/lib/mailman/data /var/lib/mailman
  rsync $common_args --compress --delete $main_server:/var/lib/mailman/archives /var/lib/mailman
  cd /var/lib/mailman/bin && ./genaliases
  echo "############################################################"
  echo "############################################################"
  menu
}
function beenden {
        clear
        exit
}
menu
while [ $eingabe != "0" ]
do
case $eingabe in
        0) beenden
            ;;
        1) install
            ;;
        2) db_migration
            ;;
        3) www_migration
            ;;
        4) mail_migration
            ;;
        5) files_migration
            ;;
        6) mailman_migration
            ;;
esac    
done

@thoatswold
Copy link

Translation into English, with migration of /etc/apache2/sites-available and /etc/apache2/sites-enabled included. Not yet tested.

#!/bin/bash
#
  echo "############################################################"
  echo "##                     Welcome                            ##"
  echo "##   Please take note of all instructions and             ##"
  echo "##   recommendations                                      ##"
  echo "##                                                        ##"
  echo "##   If you have questions or problems you can always     ##"
  echo "##   visit http://wiki.teris-cooper.de                    ##"
  echo "##                                                        ##"
  echo "##   Alternatively you're welcome to send an email to     ##"
  echo "##   admin [at] teris-cooper [dot] de                     ##"
  echo "############################################################"
  echo ""
  echo "Please enter the IP address of your master (remote) server:"
  read main_server


#common_args='-aPv --delete'
#common_args='-aPv --dry-run'
common_args='-aPv'
install_rsync="apt-get -y install rsync"
www_start="service apache2 start"
www_stop="service apache2 stop"
db_start="service mysql start"
db_stop="service mysql stop"

function menu {
    clear
    echo "############################################################"
    echo "##                    Main menu                           ##"
    echo "##                                                        ##"
    echo "## Install RSync on the remote server                  (1)##"
    echo "## Synchronize MySql                                   (2)##"
    echo "## Synchronize websites                                (3)##"
    echo "## Synchronize email                                   (4)##"
    echo "## Synchronize passwords, users and other files        (5)##"
    echo "## Synchronize MailMan                                 (6)##"
    echo "## Exit program                                        (0)##"
    echo "############################################################"
    read -n 1 eingabe
}

function install {
    clear
    echo "Installing RSync on the remote server..."
    ssh $main_server "$install_rsync"
    echo "Installation complete"
    menu
}

function db_migration {
    clear
  echo "###############################################################"
  echo "###############################################################"
  echo "############## Start MySql Migration              #############"
  echo "############## Step1:                             #############"
  echo "############## Back up the remote databases       #############"
  echo "###############################################################"
  echo "############## Step2:                             #############"
  echo "############## Copy the backed-up databases       #############"
  echo "###############################################################"
  echo "############## Step3:                             #############"
  echo "############## Import the databases into MySql    #############"
  echo "###############################################################"
  echo "###############################################################"
  echo " "
  echo "Back up the remote databases............................................................."
  echo "Please enter the MySql password for the root user on the remote server $main_server:....."
  read mysqlext
  ssh $main_server "mysqldump -u root -p$mysqlext --all-databases > /root/mysql/fulldump.sql"
  clear
  echo "Copy the backup.........................................................................."
  rsync $common_args $main_server:/root/mysql/ /root/mysql
  clear
  echo "Import the backup........................................................................"
  echo "Please enter the MySql password for the root user on this server:........................"
  read mysql2
  mysql -u root -p$mysql2 < /root/mysql/fulldump.sql
  clear
  echo "Check and repair the databases..........................................................."
  mysqlcheck -p -A --auto-repair
  echo "###############################################################"
  echo "###############################################################"
  menu
}

function www_migration {
    clear

  echo "############################################################"
  echo "############################################################"
  echo "################## Web Migration          ##################"
  echo "################## Step1:                 ##################"
  echo "################## Stop the webserver     ##################"
  echo "############################################################"
  echo "################## Step2:                 ##################"
  echo "################## Start the migration    ##################"
  echo "############################################################"
  echo "################## Step3:                 ##################"
  echo "################## Start the webserver    ##################"
  echo "############################################################"
  $www_stop
  rsync $common_args --compress --delete $main_server:/var/www/ /var/www
  rsync $common_args --compress --delete $main_server:/var/log/ispconfig/httpd/ /var/log/ispconfig/httpd
  $www_start
  echo "############################################################"
  echo "############################################################"
  menu
}

function mail_migration {
    clear
  echo "############################################################"
  echo "############################################################"
  echo "################## Mail Migration         ##################"
  echo "################## Step1:                 ##################"
  echo "################## Migrate vmail          ##################"
  echo "############################################################"
  echo "################## Step2:                 ##################"
  echo "################## Migrate vmail logs     ##################"
  echo "############################################################"
  rsync $common_args --compress --delete $main_server:/var/vmail/ /var/vmail
  rsync $common_args --compress --delete $main_server:/var/log/mail.* /var/log/
  echo "############################################################"
  echo "############################################################"
  menu
}

function files_migration {
    clear
  echo "############################################################"
  echo "############################################################"
  echo "############# Files Migration                        #######"
  echo "############# Step1:                                 #######"
  echo "############# Copy /var/backup                       #######"
  echo "############################################################"
  echo "############# Step2:                                 #######"
  echo "############# Copy /etc/passwd to /root/old-server   #######"
  echo "############################################################"
  echo "############# Step3:                                 #######"
  echo "############# Copy /etc/group to /root/old-server    #######"
  echo "############################################################"
  echo "############# Please manually install passwd+group   #######"
  echo "############# (see readme.md)                        #######"
  echo "############################################################"
  echo "############# Step4:                                 #######"
  echo "############# Copy /etc/apache2/sites-available      #######"
  echo "############################################################"
  echo "############# Step5:                                 #######"
  echo "############# Copy /etc/apache2/sites-enabled        #######"
  echo "############################################################"
  rsync $common_args $main_server:/var/backup/ /var/backup
  rsync $common_args $main_server:/etc/passwd /root/old-server/
  rsync $common_args $main_server:/etc/group  /root/old-server/
  rsync $common_args $main_server:/etc/apache2/sites-available/ /etc/apache2/sites-available
  rsync $common_args $main_server:/etc/apache2/sites-enabled/ /etc/apache2/sites-enabled
  echo "############################################################"
  echo "############################################################"
  menu
}

function mailman_migration {
    clear
  echo "############################################################"
  echo "############################################################"
  echo "############ Mailman migration                 #############"
  echo "############################################################"
  rsync $common_args --compress --delete $main_server:/var/lib/mailman/lists /var/lib/mailman
  rsync $common_args --compress --delete $main_server:/var/lib/mailman/data /var/lib/mailman
  rsync $common_args --compress --delete $main_server:/var/lib/mailman/archives /var/lib/mailman
  cd /var/lib/mailman/bin && ./genaliases
  echo "############################################################"
  echo "############################################################"
  menu
}
function beenden {
        clear
        exit
}
menu
while [ $eingabe != "0" ]
do
case $eingabe in
    0) beenden
    ;;
    1) install
    ;;
    2) db_migration
    ;;
    3) www_migration
    ;;
    4) mail_migration
    ;;
    5) files_migration
    ;;
    6) mailman_migration
    ;;
esac    
done

@t-bo
Copy link

t-bo commented Dec 12, 2015

Above script return:
41: read: Illegal option -n
42: Syntax error: "}" unexpected

@budgierless
Copy link

hi,
Ispconfig version 3.1 will be out in a few weeks as it currently set as 96% complete. so my question is will your ispconfig server to server migration script get updated so that it is able to also port from ispconfig3.0 to 3.1 while migrating?

@fbc
Copy link

fbc commented Apr 13, 2016

I recommend both servers be the same. So update your 3.0 install to 3.1 and make sure everything work before the migration.

@GitHubFeeds
Copy link

GitHubFeeds commented Sep 7, 2016

Testing the script (3th one) by thoatswold on an IspConfig 3.1 (beta) server. For now there is one thing going wrong and that's about the mysqldump directory at the 'old' server which does not exist yet. So create a directory 'mysql' within your root user directory.

Suggestion :
Use 'ssh-keygen' and 'ssh-copy-id root@ip master server / old ipsconfig server' so you do not have to provide passwords all the time.

@xavidp
Copy link

xavidp commented Oct 11, 2016

Hi, thanks for sharing. I also needed to make a few changes:

  • added the letsencrypt folder and settings from the former ispconfig server, otherwise the new server didn't load apache at all due to missing files indicated in the corresponding apache configuration files.
  • added a command to create the /root/mysql folder expected in the source server.
  • forced to continue the mysql dump even if some minor issue is found in one table for some reason.

I left the modified version from the one shared in comments section in a new github repo, in case, you want to pull changes into your script.

https://github.com/xavidp/bashscripts/blob/master/migrateispconfig.sh

Cheers

@lennysh
Copy link

lennysh commented Dec 17, 2016

What are the methods of restoring the passwd's and groups?

-=-=-=-=-=-=-=-

Nevermind, assuming it's a simple copy/paste between files?

@lennysh
Copy link

lennysh commented Dec 17, 2016

Getting internal server error 500 on all the sites except the control panel itself. It appears to run and act fine. Anything I missed?

@joejelliss
Copy link

I'm sorry, this script is deleting very important files from my webserver. This is not acceptable. So i think the migration Tool is my last chance :-(

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