Create a WordPress staging site through shell script

Creating a wordpress staging environment requires 4 things. Here we are assuming that the staging environment is on the same server. Requirements for creating a wordpress staging environement Clone Database - Each Time Copy the code - Only the wp-content folder Edit wp-config to point to the Staging Database (single site only) plus the Staging Domain (multisite) - Once Only Update the wp-options table with the Staging Domain (single site), Update the wp_blogs, wp_site, wp_options, wp_1_options, etc tables with the Staging Domain (multisite) - Each Time So how to to achive creating a wordpress staging environement with a single script? Here are the steps. Step 1: Create staging.sh and define variables Create a file named staging.sh inside a directory named staging (preferably outside your public_html folder) Define all the variables related to your production and staging database connection as shown below [crayon-59ebd630d9416784337038/] Step 2: MySQL Dump of the Production database Add below code to staging.sh file to get MySQL Dump of the current production database [crayon-59ebd630d9420121365970/] Step 3: Export the Database to the Staging database Again...
Read More

Shell script to backup database and send it to remote server automatically

This article explains how to create a database backup script to send the backup to remote server  without any manual intervention. For security reasons or to enable disaster recovery it is important to keep database backup copies on some additional server outside your network. The process to create a script for database backup and to autosend it to a remote server is not really so complicated as many would think. To make it simpler let's divide the whole task in 3 different sub tasks Create a backup file of your database. Authorize the origin server i.e. Your current server to send the files to the remote server (So that the remove server knows that it is receiving the files from a genuine source) Create a script to simply SCP the files from the origin server to the remove server Above mentioned are mandatory steps. Additionally you may also want to create a log file to log the status of every step just in...
Read More