Articles in this section

How to restore a Plesk server on a new Linux server from file system?

kb: how-to Plesk for Linux FR:PPM-2081 disaster

Applicable to:

  • Plesk for Linux

Question

  • How to restore a Plesk server on a new Linux server from file system?
  • How to execute disaster recovery in order to restore a Plesk server on a brand new Linux Plesk server?
  • How to restore a Plesk server on a brand new Linux Plesk server by using disk drive data only?

Answer

In order to restore a Plesk server on another Linux server by using the steps below, the new Plesk server must meet all of the following requirements:

  • The versions of the following components on the newly set up server must be the same as the versions used on the old server:

    • Operating system version
    • Plesk version
    • MySQL or MariaDB version
  • A valid Plesk license must be activated on the new server

  • The same exact set of Plesk extensions must be installed on the new server

    Note: Several Plesk extensions, for example Plesk Premium Email and Plesk Email Security need additional setup. Make sure all necessary packages of extensions are installed in Extensions > <extension_name> > Open.

Since the steps that need to be executed are rather complex, if you prefer to let Plesk professionals handle the restoration, contact the Plesk professional services at https://www.plesk.com/professional-services/


When all prerequisites mentioned above are met, you must enter the destination (new) Plesk server and execute the following steps

  1. Log into the destination server via SSH

    Warning: Before you follow the steps below, your Linux system administrator must first mount the hard drive from the old (source) Linux server to the /old path on the new (destination) Linux server.

  2. Create database backups while using the old database server data directory:

    2.1. Stop MySQL/MariaDB on the server by executing the following command:

    # systemctl stop mysql; systemctl stop mariadb

    2.2. Open /etc/my.cnf for editing with your favorite command-line ext editor
    2.3. Set the datadir parameter in /etc/my.cnf to point towards the MySQL database path of the old hard drive (the expected path is /old/var/lib/mysql):

    CONFIG_TEXT: datadir=/old/var/lib/mysql

    2.4. Start MySQL/MariaDB

    # systemctl start mysql; systemctl start mariadb

    2.5 Create dumps of all MySQL/MariaDB 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

    2.6. Stop MySQL/MariaDB again

    # systemctl stop mysql; systemctl stop mariadb

    2.7. Revert the datadir parameter in /etc/my.cnf to its original value:

    CONFIG_TEXT: datadir=/var/lib/mysql

    2.8. Start MySQL/MariaDB service again

    # systemctl start mysql; systemctl start mariadb

    2.9. Restore the databases:

    # for f in *.sql ; do dbname=$(echo $f | sed -e 's/\(.sql\)$//g'); MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -e "create database $dbname"; MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -D$dbname < $f; echo "$dbname restored" ; done

  3. Restore the Plesk database from the latest available dump:

    3.1. Stop the Plesk service:

    # service psa stopall

    3.2. Start the database server:

    # systemctl start mysql; systemctl start mariadb

    3.3. 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

  4. Copy the Plesk database password file:

    # cp -rpf /old/etc/psa/.psa.shadow /etc/psa/.psa.shadow

  5. 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
    # systemctl restart mysql; systemctl restart mariadb

    Note: Verify the database server is accessible after this step, with the command MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin

  6. Restore domain content:

    # rsync -av /old/var/www/vhosts/ /var/www/vhosts/

    Note: Process further only after rsync process is finished

  7. 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

  8. Restore additional FTP user IDs:

    # plesk db -Ne "select tmp.login as main_user, su.login as add_user from sys_users su join sys_users as tmp on su.mapped_to = tmp.id where su.mapped_to is not NULL" | while read i j; do usermod -u $(id -u $i) $j -o; done

  9. Restore the mailnames directory (mail content):

    # rsync -av /old/var/qmail/mailnames/ /var/qmail/mailnames/
    # chown -R popuser:popuser /var/qmail/mailnames/*

  10. Restore scheduled tasks:

    # rsync -av /old/var/spool/cron/ /var/spool/cron/

  11. Run the automated reconfiguration utility:

    # plesk repair all -y

    Note: In case the domains have incorrect ownerships in /var/www/vhosts/ directory, run the script below:

    # plesk db -Ne "select login,home from sys_users where mapped_to is null" | while read login home; do chown -R $login $home; done

  12. Start the Plesk service:

    # service psa start

Was this article helpful?

Comments

1 comment
Date Votes
  • For the 2.2 part it's returning me this:

    ERROR 1045 (28000): Access denied for user 'admin'@'localhost' (using password: YES)

    1

Please sign in to leave a comment.