Applicable to:
- Plesk for Linux
Question
How to restore a Plesk server on a new Linux server from file system?
How to restore Plesk installation on a new Linux server after disaster?
Added this for searchabilityAnswer
To restore a Plesk server on another Linux server with the following steps, the new server must meet the following requirements:
-
Same versions as on old server of the following:
- operating system
- Plesk version
- MySQL or MariaDB
-
A valid Plesk license is installed
-
Same set of Plesk extensions installed
Note: Several Plesk extensions, for example
Plesk Premium Email
andPlesk Email Security
need additional setup. Make sure all necessary packages of extensionsare 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:
-
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/mysql -
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
-
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/mysql -
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:
-
Stop the Plesk service:
# service psa stopall
-
Start the database server:
# service mysqld start
-
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
5 comments
This is not clear, since disaster recovery inmho, means that the old server completely crashed and the data being restored is to a new server from a offsite full server backup. Nothing mentioned here if the old drive is not there nor is the old server? Also, what if there was no way of attaching the old drive to a new server.
Please provide instructions on how to restore to a new server with a offsite full backup, or a link to that page as I couldn't find one.
article does not describe what its title is!
Disaster means you have no old server you can copy data from.
Please rewrite this article or correct the name of its subject.
The article has been changed. It's a shame, disaster recovery is something that Plesk is still missing.
Example: How do I restore a pleskserver backup that is on an (s)ftp server, on the same operating system and the same Plesk version, on a new server?
Or: I create a rsync backup of my entire server, locally on my PC.
How do I restore this with rsync on a new server, via ssh?
I removed curl from my server and then plesk-core and so on, removed.
mysql, bind, all other services are working fine, but I can't access the plesk login page. I get the http 404 code.
how to use autoinstall and preserve all my services.
Thank you.
This does not work for me.
# 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
Result:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
-bash: .sql: No such file or directory
Please sign in to leave a comment.