Kuba M
Kuba M

Reputation: 139

Plesk restore from dumps

I am planning to reinstall CentOS 6 system on dedicated server which was running Wordpress websites at Plesk 11.5 hosting program. Due to removal of php files ($#@% php update...), some Plesk dependant files have been removed and I am unable to access Plesk administration panel (to backup files via GUI). I have copied all files from /var/lib/psa/dumps to FTP server.

According to this information all of backup files are located there by default. If I copy them after reinstalling, to the same location, is it possible to completely restore websites with corresponding databases?

Upvotes: 3

Views: 2617

Answers (1)

Elvis Plesky
Elvis Plesky

Reputation: 3300

There is a comprehensive guide on how to restore Plesk for Linux installation on another server after a disaster in Plesk help center.

Plesk Onyx and Plesk 12.5

1. Important: This step is only possible if the version of MySQL server matches for both the original and new server's one.

Start the MySQL 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

and dump the 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, 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 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 -D$dbname < $f; echo "$dbname restored" ; done

2. Restore the Plesk databases from the available dump:

Stop the Plesk service:

# service psa stopall

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

3. Copy the Plesk database password file:

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

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

Note: make sure that MySQL is accessible using MYSQL_PWD=cat /etc/psa/.psa.shadow mysql -u admin

5. Restore domain content:

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

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

7. Restore the mailnames directory (mail content):

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

8. For Plesk Onyx and Plesk 12.5, run fully automated reconfiguration utility:

# plesk repair all -y

9. Start the Plesk service:

# service psa start

Plesk 9.x - 12.0

1. Important: This step is only possible if the version of MySQL server matches for both the original and new server's one.

Start the MySQL 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

and dump the databases:

# MYSQL_PWD=`cat /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 /etc/psa/.psa.shadow` mysqldump -u admin --databases $dbname > $dbname.sql ; done

Stop MySQL, 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 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 -D$dbname < $f; echo "$dbname restored" ; done

2. Restore the Plesk databases from the available dump:

Stop the Plesk service:

# service psa stopall

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

3. Copy the Plesk database password file:

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

4. Copy the encryption key to the new server:

# 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

Note: it also may be necessary to chmod and chown the file:

# chmod 0600 /etc/psa/private/secret_key
# chown psaadm:root /etc/psa/private/secret_key

These are the correct permissions for this file:

# stat /etc/psa/private/secret_key
File: `/etc/psa/private/secret_key'
Size: 16 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 49938531 Links: 1
Access: (0600/-rw-------) Uid: ( 501/ psaadm) Gid: ( 0/ root)

Note: if after this, MySQL is not accessible with Plesk credentials ( MYSQL_PWD=cat /etc/psa/.psa.shadow mysql -u admin ), try restarting the MySQL server using service mysqld restart command.

5. Restore domain content:

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

6. Restore Plesk system users:

For Plesk 11.x-12.0, execute the following command:

# 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

For Plesk 10.x, execute the following command:

# MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -Ns -e"select s1.login, s2.login from sys_users s1 left join sys_users s2 on s2.id = s1.mapped_to where s2.login is not null" | awk '{print "/usr/local/psa/admin/sbin/usermng --map-user --user=" $1 " --mapped-to=" $2}' | sh -x

7. Restore SSL certificates:

# cp -p /old/usr/local/psa/var/certificates/* /usr/local/psa/var/certificates/

8. Restore the mailnames directory (mail content):

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

9. Repair ownership on the virtual hosts' content to fix files and directories owned by non-existent users:

# MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -Ns -e"SELECT s.home, h.www_root, s.login FROM hosting h, sys_users s WHERE s.id = h.sys_user_id" | while read home www_root login ; do content_uid=`stat --format=%u "$www_root"` ; find $home -uid $content_uid -exec chown $login '{}' + ; done

For Plesk 9.x and earlier:

# MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin -Dpsa -Ns -e"SELECT home, login FROM sys_users" | while read home login ; do content_uid=`stat --format=%u "$home/httpdocs"` ; find $home -uid $content_uid -exec chown $login '{}' + ; done

10. Regenerate the web server configuration:

For Plesk 10.x-12.0:

# /usr/local/psa/admin/sbin/httpdmng --reconfigure-all

For Plesk 8.x and 9.x:

# /usr/local/psa/admin/sbin/websrvmng –a -v

11. Repair the mail configuration:

# /usr/local/psa/admin/sbin/mchk –-with-spam

12. Restore DNS zones:

# MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin psa -Ns -e "select name from dns_zone" | awk '{ print "/usr/local/psa/admin/sbin/dnsmng --update " $1 }' | sh -x

13. Start the Plesk service:

# service psa start

Upvotes: 1

Related Questions