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 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
- Plesk version
- MySQL or MariaDB
-
A valid Plesk license should be activated on the new server
-
The same set of Plesk extensions must be installed on the new server
Note: Several Plesk extensions, for example
Plesk Premium Email
andPlesk Email Security
need additional setup. Make sure all necessary packages of extensions are installed in Extensions > <extension_name> > Open.
If you prefer to let Plesk professionals handle the restoration, contact the Plesk professional services here: https://www.plesk.com/professional-services/
In the following steps, it is assumed that the hard drive from the old server is mounted to the directory /old
on the new server.
-
Connect to the new Linux server using SSH
-
Create database backups with old server's data directory:
2.1. Start the MySQL/MariaDB 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/mysql2.2. 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.3. Stop MySQL/MariaDB service and revert the
datadir
parameter in/etc/my.cnf
to its original value:# service mysqld stop
# cat /etc/my.cnf | grep datadir
datadir=/var/lib/mysql2.4. Start 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 -
Restore the Plesk database from the latest available dump:
3.1. Stop the Plesk service:
# service psa stopall
3.2. Start the database server:
# service mysqld start
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
# service mysqld restartNote: 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
mailnames
directory (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
1 comment
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.