If you need to restore a Plesk server on a new Linux machine, follow this guide for a step-by-step approach. This process involves restoring Plesk data from the file system, databases, and user content. Please ensure that the new server matches the configuration of the original one.

Prerequisites

  • The Operating System, Plesk version, and MySQL/MariaDB versions on the new server should match those on the original server.
  • Ensure a valid Plesk license is activated on the new server.
  • Install the same Plesk extensions on the new server.
  • In this guide, we assume the original server's hard drive is mounted at /old on the new server.

Note: Some Plesk extensions, such as Plesk Premium Email and Plesk Email Security, may require additional configuration. Refer to Extensions > <extension_name> > Open for setup instructions.

Optional: Professional Assistance

Our migration team can help you with this. But if you'd prefer to have Plesk's professionals handle the restoration, contact Plesk Professional Services.

Steps to Restore the Plesk Server

1. Connect to the New Server and Create Database Backups

  1. SSH into the new server.
  2. Backup databases using the data directory from the original server:
    1. Configure MySQL/MariaDB to use the old data directory:
      sed -i 's|datadir=.*|datadir=/old/var/lib/mysql|' /etc/my.cnf
    2. Generate database dumps:
      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
    3. Revert datadir to its original location:
      sed -i 's|datadir=.*|datadir=/var/lib/mysql|' /etc/my.cnf
    4. Restart the MySQL/MariaDB service 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 -e "create database $dbname"; MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -u admin -D$dbname < $f; echo "$dbname restored" ; done

2. Restore the Plesk Database

  1. Stop the Plesk services:
    service psa stopall
  2. Start the MySQL/MariaDB service:
    service mysqld start
  3. Import the latest Plesk 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. Transfer and set permissions for the encryption key:
    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
  6. Restart MySQL/MariaDB:
    service mysqld restart

    Note: Verify MySQL is accessible using:

    MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -u admin

3. Restore Domain and User Data

  1. Restore domain content:
    rsync -av /old/var/www/vhosts/ /var/www/vhosts/
  2. 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='\''" $2 "'\'' /usr/local/psa/admin/sbin/usermng --add-user --user=" $1 " --homedir=" $3 " --shell=" ($4?$4:"/bin/false")}' | sh -x
  3. 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
  4. Restore mail directory:
    rsync -av /old/var/qmail/mailnames/ /var/qmail/mailnames/
    chown -R popuser:popuser /var/qmail/mailnames/*
  5. Restore scheduled tasks:
    rsync -av /old/var/spool/cron/ /var/spool/cron/

4. Run Automated Reconfiguration and Final Setup

  1. Run Plesk repair to automatically configure settings:
    plesk repair all -y
  2. If domains have incorrect ownerships, run the following script to fix:
    plesk db -Ne "select login,home from sys_users where mapped_to is null" | while read login home; do chown -R $login $home; done
  3. Start Plesk services:
    service psa start

Important Considerations

Test these steps in a staging environment first, and refer to the latest Plesk documentation to confirm compatibility with your setup.

Did this answer help? 0 People found this helpful (0 Votes)