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 EmailandPlesk Email Securityneed 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
-
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
/oldpath on the new (destination) Linux server. -
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.cnffor editing with your favorite command-line ext editor
2.3. Set thedatadirparameter in/etc/my.cnfto 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
datadirparameter in/etc/my.cnfto 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
-
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
-
Copy the Plesk database password file:
# cp -rpf /old/etc/psa/.psa.shadow /etc/psa/.psa.shadow
-
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 mariadbNote: Verify the database server is accessible after this step, with the command
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -
Restore domain content:
# rsync -av /old/var/www/vhosts/ /var/www/vhosts/
Note: Process further only after rsync process is finished
-
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
-
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
-
Restore the
mailnamesdirectory (mail content):# rsync -av /old/var/qmail/mailnames/ /var/qmail/mailnames/
# chown -R popuser:popuser /var/qmail/mailnames/* -
Restore scheduled tasks:
# rsync -av /old/var/spool/cron/ /var/spool/cron/
-
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
-
Start the Plesk service:
# service psa start
Comments
For the 2.2 part it's returning me this:
ERROR 1045 (28000): Access denied for user 'admin'@'localhost' (using password: YES)
Please sign in to leave a comment.