Created
March 7, 2014 12:39
-
-
Save yorch/9410737 to your computer and use it in GitHub Desktop.
ISPConfig 3 script to move installation from one server to another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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 :-(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.