-
-
Save yorch/9410737 to your computer and use it in GitHub Desktop.
#!/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 |
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
Above script return:
41: read: Illegal option -n
42: Syntax error: "}" unexpected
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?
I recommend both servers be the same. So update your 3.0 install to 3.1 and make sure everything work before the migration.
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.
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
What are the methods of restoring the passwd's and groups?
-=-=-=-=-=-=-=-
Nevermind, assuming it's a simple copy/paste between files?
Getting internal server error 500 on all the sites except the control panel itself. It appears to run and act fine. Anything I missed?
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 :-(
Source: https://raw.githubusercontent.com/teris/Debian-ISPConfig3-migration/master/migration.sh