Server - Contents

Wordpress Backup

revised 10-Sep-2021

The Wordpress application has become increasing complex, particularly if one has added plugins etc. The following restore method may work for simple setups only.

Backup Procedure

Part A: The application framework

Following the same framework and example naming outlined in setting up Wordpress where the application is in the sub-directory /var/www/wordpress, one logons the server, via PuTTY, and enters the following commands:

sammy@imega: cd /var/www/
sammy@imega /var/www/: sudo tar czf wordpressYYMMDD.tar.gz wordpress/
sammy@imega /var/www/: sudo mv wordpressYYMMDD.tar.gz /home/sammy

//where YYMMDD stands for the year, month and day – the day of the backup.

Part B: The Wordpress Database

Method 1: Via Webmin, go to [Servers]->[MySQL Database Server], click on the Wordpress database (wordpressdb). At the bottom of the page of tables, there is a button [Backup Database] then activate the button left of [Download in Browser], then click finally the button [Backup Now]. The following dialogue box gives one the option to download the database backup (.sql) to the Download folder. Rename the file: wordpressdbYYMMDD.sql as per the download date.

Method 2: Logon to the server, via PuTTY as the regular user, and enter the following commands:

sammy@imega: sudo mysqldump -u root -p[mysqlrootpassword] wordpressdb > wordpressdbYYMMDD.sql

Note: that there is no space nor brackets between “-p” and the mysqlrootpassword to be used is from the iRedmail setup (logon to the postmaster's mailbox (eg. postmaster@example.com) to retrieve such details).

Using FileZilla, one can then download these two files (eg.wordpressYYMMDD.tar.gz and wordpressdbYYMMDD.sql ) and store them securely.

Restore Procedure

First Wordpress Database, then the Application Backup

In reverse order from the backup procedure, one first restores the database. Using FileZilla, upload to the regular user's home directory (eg. /home/sammy), the two backup files; the wordpressdbYYMMDD.sql file and the wordpressYYMMDD.tar.gz. Logon to the server, via PuTTY, and enter the following commands:

sammy@imega: sudo mysqladmin -u root -p[mysqlrootpassword] drop wordpressdb
sammy@imega: sudo mysqladmin -u root -p[mysqlrootpassword] create wordpressdb
sammy@imega: sudo mysql -u root -p[mysqlrootpassword] wordpressdb < wordpressdbYYMMDD.sql
sammy@imega: sudo tar xzf wordpressYYMMDD.tar.gz
sammy@imega: sudo rm -r /var/www/wordpress   // remove old broken application
sammy@imega: sudo mkdir /var/www/wordpress
sammy@imega: sudo mv wordpress /var/www/
sammy@imega: sudo chown -R www-data:www-data /var/www/wordpress/
sammy@imega: sudo chmod -R 755 /var/www/wordpress/

Note: If the restore is for correcting a damaged database, then the database alone could be sufficient.

Tip#01 If in the backup, one is changing to another domain-name or another directory location, the wordpressdbYYMMDD.sql must be edited to reflect the new domain-name or new directory location.

To do this, open wordpressdbYYMMDD.sql in a text editor (eg. Notepad++) and, using “Find and Replace”, find all entries with the old doman [eg. http://example.com] with new [eg. http://example-new.com]. Similarly, the old directory local (eg. /var/www/html/wordpress) replaced with the new one (eg. /var/vsite/wordpress).

Wordpress Wordpress Backup