Synology usage series 28 – Mirroring wordpress from webhost to synology box – the automatic way


Assumption

– the live site is www.mydomain.com
– the mirrored site hosted on NAS is backup.mynasdomain.com

Part 1 – Preparation

DNS Stuff

Since we are mirroring the website to our syno box, so the mirrored site hosted on syno box also requires its own domain name.

  1. Login to DNS provider and add a subdomain for the mirrored wordpress, i.e. backup.mynasdomain.com
  2. If your syno box have dynamic ip, update the dynamic dns script for the new subdomain.

NAS setup

Next we need to perform setup on the NAS. Login to synology admin console using web browser.

NAS – Add a Virtual Host for the mirrored site

  1. Navigate to Control Panel / Network Services / Web Services / Web Applications
  2. Click the Virtual Host button
  3. Click ‘Create’ button
  4. Sub Folder: public_html
    Hostname: backup.mynasdomain.com
    Protocol: HTTP ( or HTTPS if you prefer encryption)

    *** The sub folder must match the directory of web host that we are going to mirror. So, to mirror the public_html directory of the web host account, we define public_html as sub folder here.

NAS – MySQL setup

Create a mysql database and database user to store the mirrored wordpress database.

The name of database, database user and password must be same as webhost setup.


# /usr/syno/mysql/bin/mysql --host=localhost --user=root --password
Enter password: <enter the mysql password of root>
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create user 'user_wordpress'@'localhost' identified by '12345678';
Query OK, 0 rows affected (0.02 sec)
mysql> create user 'user_wordpress'@'127.0.0.1' identified by '12345678';
Query OK, 0 rows affected (0.02 sec)
mysql> create database wordpress_backup character set = utf8 collate = utf8_general_ci;
Query OK, 1 row affected (0.04 sec)
mysql> GRANT ALL PRIVILEGES ON wordpress_backup.* TO 'user_wordpress'@'127.0.0.1' WITH GRANT OPTION;
Query OK, 0 rows affected (0.02 sec)
mysql> GRANT ALL PRIVILEGES ON wordpress_backup.* TO 'user_wordpress'@'localhost' WITH GRANT OPTION;
Query OK, 0 rows affected (0.02 sec)

Web Host Setup

Install any wordpress backup plugin, setup the plugin to generate backup daily before our cron job.

Since my script will looks for database backup file with the following filename

prefix_yyyy-mm-dd.zip

So the requirement for the backup plugin:

  • Allow user to customize the backup file name
  • Able to zip the backup file

Previously I’m using EZ One Click Backup Plugin which never able to perform any schedule backup. BackWPup plugin is working great for my site.

However BackWPup do generate backup file name like this

prefix_dddd-mm-yy_timestamp.zip

So I need to modify the plugin source code to remove the timestamp from the filename, otherwise my script will failed to lookup the db backup file.

To modify the plugin, login to wordpress admin, go to plugin editor.

Edit backwpup/job/job_start.php

Looks for the lines below

//set Backup file Name
$backwpup_static['backupfile']=$backwpup_static['JOB']['fileprefix'].backwpup_date_i18n('Y-m-d_H-i-s').$backwpup_static['JOB']['fileformart'];

Remove the _H-i-s and save.

//set Backup file Name
$backwpup_static['backupfile']=$backwpup_static['JOB']['fileprefix'].backwpup_date_i18n('Y-m-d').$backwpup_static['JOB']['fileformart'];

After modified the php code, we can start create a database backup job.

Job Type:

BackWPUp Plugin - Add Job - Job Type

BackWPUp Plugin - Add Job - Job Type

Click database backup.

Database Jobs:

BackWPUp Plugin - Add Job - Database Jobs

BackWPUp Plugin - Add Job - Database Jobs

Just check all the tables you want to backup.

Backup to Folder:

BackWPUp Plugin - Add Job - Backup to Folder

BackWPUp Plugin - Add Job - Backup to Folder

Define where to store the database backup file. To make things simple, just generate the backup file under the wp-content directory. For example:

/home/id/public_html/wp-content

Job Schedule:

BackWPUp Plugin - Add Job - Job Schedule

BackWPUp Plugin - Add Job - Job Schedule

Click the Activate scheduling.

Click basic scheduling.

Click daily. Define the hour to generate the db backup.

Backup File:

BackWPUp Plugin - Add Job - Define backup file name

BackWPUp Plugin - Add Job - Define backup file name

Finally we need to define the backup file name. Input the prefix and select zip file format.





Leave a Reply

Your email address will not be published. Required fields are marked *