How to restore Plesk installation on a new Linux server after disaster

Created:

2016-11-16 12:58:41 UTC

Modified:

2017-08-16 16:57:54 UTC

3

Was this article helpful?


Have more questions?

Submit a request

How to restore Plesk installation on a new Linux server after disaster

Applicable to:

  • Plesk for Linux

Table of contents

Question

During a disaster recovery, it is necessary to set up a new Plesk instance and migrate all server settings and customers data from the old server. For some reason, it is not possible to use the solution described in this article: How to restore Plesk from a hard disk drive if the Operating System is broken and the HDD with the old installation is mounted to the new server?

Answer

If you prefer to let Plesk professionals handle the migration or upgrade job for you please check out Plesk professional services options on our website: https://www.plesk.com/professional-services/

Connect to the new server using SSH. It is assumed that the hard drive from the old server is mounted to the /old directory on the new server.

Note: on the new server, the same version of Plesk as on the old one should be installed, and it should be licensed properly. Also, the same set of extensions should be installed on the new server.

Plesk Onyx and Plesk 12.5

  1. Important: This step is only possible if the version of MySQL server matches for both the original and new server's one.

    Start the MySQL server with the datadir parameter in /etc/my.cnf pointing to the MySQL database location on the old drive ( /old/var/lib/mysql):

    # cat /etc/my.cnf | grep datadir
    datadir=/old/var/lib/mysql

    and dump the databases:

    # MYSQL_PWD=`cat /old/etc/psa/.psa.shadow` mysql -u admin psa -Ns -e"select name from data_bases where type = 'mysql'" | while read dbname ; do MYSQL_PWD=`cat /old/etc/psa/.psa.shadow` mysqldump -u admin --databases $dbname > $dbname.sql ; done

    Stop MySQL, revert the datadir parameter in /etc/my.cnf to its original value:

    # service mysqld stop
    # cat /etc/my.cnf | grep datadir
    datadir=/var/lib/mysql

    Start MySQL and restore the databases:

    # service mysqld start 
    # for f in *.sql ; do dbname=$(echo $f | sed -e 's/\\(.sql\\)*$//g'); MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -D$dbname < $f; echo "$dbname restored" ; done
  2. Restore the Plesk databases from the available dump:

    • Stop the Plesk service:
      # service psa stopall
    • Import the database dump:
      # zcat /old/var/lib/psa/dumps/mysql.daily.dump.0.gz | MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin
  3. Copy the Plesk database password file:

    # cp -rpf /old/etc/psa/.psa.shadow /etc/psa/.psa.shadow
  4. Copy the encryption key to the new server, set the correct permissions and restart MySQL service:

    # cp /etc/psa/private/secret_key /etc/psa/private/secret_key.save
    # cp -rpf /old/etc/psa/private/secret_key /etc/psa/private/secret_key
    # chmod 0600 /etc/psa/private/secret_key
    # chown psaadm:root /etc/psa/private/secret_key
    # service mysqld restart

    Note: make sure that MySQL is accessible using MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin

  5. Restore domain content:

    # rsync -av /old/var/www/vhosts/ /var/www/vhosts/
  6. Restore Plesk system users:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -Ns -e"select s.login, a.password, s.home, s.shell from sys_users s, accounts a where a.id = s.account_id" | awk '{ print "PSA_PASSWD=\\x27" $2 "\\x27 /usr/local/psa/admin/sbin/usermng --add-user --user=" $1 " --homedir=" $3 " --shell=" ($4?$4:"/bin/false")}' | sh -x
  7. Restore content of the mailnames folder:

    # rsync -av /old/var/qmail/mailnames/ /var/qmail/mailnames/
    # chown -R popuser:popuser /var/qmail/mailnames/*
  8. For Plesk Onyx and Plesk 12.5, run fully automated reconfiguration utility:

    # plesk repair all -y
  9. Start the Plesk service:
    # service psa start

Plesk 9.x - 12.0

  1. Important: This step is only possible if the version of MySQL server matches for both the original and new server's one.

    Start the MySQL server with the datadir parameter in /etc/my.cnf pointing to the MySQL database location on the old drive ( /old/var/lib/mysql):

    # cat /etc/my.cnf | grep datadir
    datadir=/old/var/lib/mysql

    and dump the databases:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin psa -Ns -e"select name from data_bases where type = 'mysql'" | while read dbname ; do MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysqldump -u admin --databases $dbname > $dbname.sql ; done

    Stop MySQL, revert the datadir parameter in /etc/my.cnf to its original value:

    # service mysqld stop
    # cat /etc/my.cnf | grep datadir
    datadir=/var/lib/mysql

    Start MySQL and restore the databases:

    # service mysqld start 
    # for f in *.sql ; do dbname=$(echo $f | sed -e 's/\\(.sql\\)*$//g'); MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -D$dbname < $f; echo "$dbname restored" ; done
  2. Restore the Plesk databases from the available dump:

    • Stop the Plesk service:
      # service psa stopall
    • Import the database dump:
      # zcat /old/var/lib/psa/dumps/mysql.daily.dump.0.gz | MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin
  3. Copy the Plesk database password file:

    # cp -rpf /old/etc/psa/.psa.shadow /etc/psa/.psa.shadow
  4. Copy the encryption key to the new server:

    # cp /etc/psa/private/secret_key /etc/psa/private/secret_key.save
    # cp -rpf /old/etc/psa/private/secret_key /etc/psa/private/secret_key

    Note: it also may be necessary to chmod and chown the file:

    # chmod 0600 /etc/psa/private/secret_key
    # chown psaadm:root /etc/psa/private/secret_key

    These are the correct permissions for this file:

    # stat /etc/psa/private/secret_key
    File: `/etc/psa/private/secret_key'
    Size: 16 Blocks: 8 IO Block: 4096 regular file
    Device: fd00h/64768d Inode: 49938531 Links: 1
    Access: (0600/-rw-------) Uid: ( 501/ psaadm) Gid: ( 0/ root)

    Note: if after this, MySQL is not accessible with Plesk credentials ( MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin ), try restarting the MySQL server using service mysqld restart command.

  5. Restore domain content:

    # rsync -av /old/var/www/vhosts/ /var/www/vhosts/
  6. Restore Plesk system users:

    For Plesk 11.x-12.0, execute the following command:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -Ns -e"select s.login, a.password, s.home, s.shell from sys_users s, accounts a where a.id = s.account_id" | awk '{ print "PSA_PASSWD=\\x27" $2 "\\x27 /usr/local/psa/admin/sbin/usermng --add-user --user=" $1 " --homedir=" $3 " --shell=" ($4?$4:"/bin/false")}' | sh -x

    For Plesk 10.x, execute the following command:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -Ns -e"select s1.login, s2.login from sys_users s1 left join sys_users s2 on s2.id = s1.mapped_to where s2.login is not null" | awk '{print "/usr/local/psa/admin/sbin/usermng --map-user --user=" $1 " --mapped-to=" $2}' | sh -x
  7. Restore SSL certificates:

    # cp -p  /old/usr/local/psa/var/certificates/* /usr/local/psa/var/certificates/
  8. Restore content of the mailnames folder:

    # rsync -av /old/var/qmail/mailnames/ /var/qmail/mailnames/
    # chown -R popuser:popuser /var/qmail/mailnames/*
  9. Repair ownership on the virtual hosts' content to fix files and directories owned by non-existent users:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -Ns -e"SELECT s.home, h.www_root, s.login FROM hosting h, sys_users s WHERE s.id = h.sys_user_id" | while read home www_root login ; do content_uid=`stat --format=%u "$www_root"` ; find $home -uid $content_uid -exec chown $login '{}' + ; done

    For Plesk 9.x and earlier:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -Ns -e"SELECT home, login FROM sys_users" | while read home login ; do content_uid=`stat --format=%u "$home/httpdocs"` ; find $home -uid $content_uid -exec chown $login '{}' + ; done
  10. Regenerate the web server configuration:

    For Plesk 10.x-12.0:

    # /usr/local/psa/admin/sbin/httpdmng --reconfigure-all

    For Plesk 8.x and 9.x:

    # /usr/local/psa/admin/sbin/websrvmng –a -v
  11. Repair the mail configuration:

    # /usr/local/psa/admin/sbin/mchk –-with-spam
  12. Restore DNS zones:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin psa -Ns -e  "select name from dns_zone" | awk '{ print "/usr/local/psa/admin/sbin/dnsmng --update " $1 }' | sh -x
  13. Start the Plesk service:

    # service psa start
Have more questions? Submit a request
Please sign in to leave a comment.