#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: http://mirrors.slickstack.io/bash/ss-sync-staging.txt ################################# #### path: /var/www/ss-sync-staging ################################################################ #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Syncs relevant files and database from production site to the staging site ########### #### module version: WordPress 5.5.x + MySQL 8.0.x + ############################################### #### sourced by: ss core cron jobs ################################################################# #################################################################################################### ## SS-SYNC DUPLICATES ALL RELEVANT FILES FROM PRODUCTION TO STAGING (BUT NOT UPLOADS) ## ## STAGING SITES WILL MIRROR (NGINX ALIAS) ALL MEDIA UPLOADS FROM PRODUCTION ## ## include SlickStack configuration ## source /var/www/ss-config ## include SlickStack functions ## source /var/www/ss-functions #################################################################################################### #### SS-Sync-Staging: Message (Begin Script) ####################################################### #################################################################################################### ## this is a simple message that announces to the shell the purpose of this bash script ## ## it will only be noticed by sudo users who manually call ss core bash scripts ## ## echo message ## echo -e "${PURPLE}Running ss-sync-staging: Syncs relevant files and database from production site to the staging site... ${NOCOLOR}" sleep "$SLEEP_MESSAGE_BEGIN" #################################################################################################### #### SS-Sync-Staging: Copy All Relevant Files From Production To Staging ########################### #################################################################################################### ## here we copy over everything from production to staging besides uploads (media files) ## ## schedule ss-clean beforehand in order to remove various (large) junk files ## ## only if staging site not disabled in ss-config ## if [[ "$STAGING_SITE" != "false" ]] && [[ "$SS_APP" == "wordpress" || -z "$SS_APP" ]]; then ## create staging database ## sudo mysql -e "CREATE DATABASE IF NOT EXISTS wordpress_staging;" ## copy WordPress Core directories (wp-admin and wp-includes) ## rsync /var/www/html/wp-admin/ /var/www/html/staging/wp-admin rsync /var/www/html/wp-includes/ /var/www/html/staging/wp-includes ## copy WordPress Core (PHP) files in web root ## # --exclude-from="/var/www/meta/exclude.txt" rsync --exclude="wp-config*.php*" --include="index.php" --include="wp-*.php" --exclude="*" /var/www/html/ /var/www/html/staging ## copy wp-content files over (skips media uploads) ## rsync --max-size=5mb --exclude="mu-plugins*" --exclude="uploads*" /var/www/html/wp-content/ /var/www/html/staging/wp-content ## remove potential run-on subdirectories ## rm /var/www/html/staging/staging* #################################################################################################### #### SS-Sync-Staging: Copy Database From Production To Staging (Modify Table Prefix) ############### #################################################################################################### ## schedule ss-dump beforehand to dump the MySQL database optimally before ss-sync runs ## ## table prefix changed to staging_ (hardcoded) and minor search/replace occurs ## ## cleanup tmp files ## rm /var/www/meta/staging*.sql* rm /tmp/staging*.sql* ## duplicate production SQL dump to temporary staging SQL dump ## cp /var/www/meta/wp.sql /tmp/staging.sql ## change production table prefixes to staging_ prefix (shared database) ## if [[ -z "$DB_PREFIX" ]]; then sed -i "s#wp_#staging_#g" /tmp/staging.sql else sed -i "s#${DB_PREFIX}#staging_#g" /tmp/staging.sql fi ## replace all URLs with staging ## sed -i "s#https://$SITE_DOMAIN#https://$SITE_DOMAIN/staging#g" /tmp/staging.sql sed -i "s#http://$SITE_DOMAIN#https://$SITE_DOMAIN/staging#g" /tmp/staging.sql sed -i "s#//$SITE_DOMAIN#//$SITE_DOMAIN/staging#g" /tmp/staging.sql sed -i "s#$SITE_DOMAIN#$SITE_DOMAIN/staging#g" /tmp/staging.sql ## fix potential run-on paths in temporary staging SQL dump ## sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging/staging/staging/staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging/staging/staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging/staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging/staging#staging#g" /tmp/staging.sql sed -i "s#staging/staging#staging#g" /tmp/staging.sql ## fix potential excessive forward-slashes in temporary staging SQL dump ## sed -i "s#staging///////////////#staging/#g" /tmp/staging.sql sed -i "s#staging//////////////#staging/#g" /tmp/staging.sql sed -i "s#staging/////////////#staging/#g" /tmp/staging.sql sed -i "s#staging////////////#staging/#g" /tmp/staging.sql sed -i "s#staging///////////#staging/#g" /tmp/staging.sql sed -i "s#staging//////////#staging/#g" /tmp/staging.sql sed -i "s#staging/////////#staging/#g" /tmp/staging.sql sed -i "s#staging////////#staging/#g" /tmp/staging.sql sed -i "s#staging///////#staging/#g" /tmp/staging.sql sed -i "s#staging//////#staging/#g" /tmp/staging.sql sed -i "s#staging/////#staging/#g" /tmp/staging.sql sed -i "s#staging////#staging/#g" /tmp/staging.sql sed -i "s#staging///#staging/#g" /tmp/staging.sql sed -i "s#staging//#staging/#g" /tmp/staging.sql ## fix potential double forward slashes between domain and subdirectory (caused by sed rules above) ## sed -i "s#/////staging#/staging#g" /tmp/staging.sql sed -i "s#////staging#/staging#g" /tmp/staging.sql sed -i "s#///staging#/staging#g" /tmp/staging.sql sed -i "s#//staging#/staging#g" /tmp/staging.sql ## fix potential run-on table prefixes ## sed -i "s#staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_staging_staging_staging_staging_staging_staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_staging_staging_staging_staging_staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_staging_staging_staging_staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_staging_staging_staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_staging_staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_staging_#staging_#g" /tmp/staging.sql sed -i "s#staging_staging_#staging_#g" /tmp/staging.sql #################################################################################################### #### SS-Sync-Staging: Fix Any Hardcoded Links In Theme Files ####################################### #################################################################################################### ## many themes (or custom-coded themes) often contain hardcoded HTML assets and links ## ## here we forcefully fix these links to ensure staging sites render properly ## ## fix hyperlinks (but not media src as they are shared with production uploads folder) ## # find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i 's#href="https://$SITE_DOMAIN#href="https://$SITE_DOMAIN/staging#g' {} + # find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i 's#href="http://$SITE_DOMAIN#href="https://$SITE_DOMAIN/staging#g' {} + # find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i 's#href="//$SITE_DOMAIN#href="https://$SITE_DOMAIN/staging#g' {} + # find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#href='https://$SITE_DOMAIN#href='https://$SITE_DOMAIN/staging#g" {} + # find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#href='http://$SITE_DOMAIN#href='https://$SITE_DOMAIN/staging#g" {} + # find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#href='//$SITE_DOMAIN#href='https://$SITE_DOMAIN/staging#g" {} + ## fix sources (mirrors to production uploads folder using Nginx alias so this is just for cleaner source code) ## # find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i 's#src="https://$SITE_DOMAIN#src="https://$SITE_DOMAIN/staging#g' {} + # find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i 's#src="http://$SITE_DOMAIN#src="https://$SITE_DOMAIN/staging#g' {} + # find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i 's#src="//$SITE_DOMAIN#src="https://$SITE_DOMAIN/staging#g' {} + # find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#src='https://$SITE_DOMAIN#src='https://$SITE_DOMAIN/staging#g" {} + # find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#src='http://$SITE_DOMAIN#src='https://$SITE_DOMAIN/staging#g" {} + # find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#src='//$SITE_DOMAIN#src='https://$SITE_DOMAIN/staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#https://$SITE_DOMAIN#https://$SITE_DOMAIN/staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#http://$SITE_DOMAIN#https://$SITE_DOMAIN/staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#//$SITE_DOMAIN#//$SITE_DOMAIN/staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#$SITE_DOMAIN#$SITE_DOMAIN/staging#g" {} + ## now we fix potential hardcoded run-on paths in theme files (caused by previous seds) ## find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging/staging/staging/staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging/staging/staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging/staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging/staging#staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/staging#staging#g" {} + ## fix potential excessive forward-slashes in theme files ## find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging///////////////#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging//////////////#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/////////////#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging////////////#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging///////////#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging//////////#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/////////#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging////////#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging///////#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging//////#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging/////#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging////#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging///#staging/#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#staging//#staging/#g" {} + ## fix potential double forward slashes between domain and subdirectory (caused by sed rules above) ## find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#/////staging#/staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#////staging#/staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#///staging#/staging#g" {} + find /var/www/html/staging/wp-content/themes/ -type f -exec sed -i "s#//staging#/staging#g" {} + ## import database ## mysql "$DB_NAME" < /tmp/staging.sql ## fix staging home and siteurl fields (no mass search/replace to avoid potential conflicts) ## mysql --execute="UPDATE ${DB_NAME}.${DB_PREFIX}options SET option_value='https://$SITE_DOMAIN' WHERE option_name='home'"; mysql --execute="UPDATE ${DB_NAME}.${DB_PREFIX}options SET option_value='https://$SITE_DOMAIN' WHERE option_name='siteurl'"; mysql --execute="UPDATE ${DB_NAME}.staging_options SET option_value='https://$SITE_DOMAIN/staging' WHERE option_name='home'"; mysql --execute="UPDATE ${DB_NAME}.staging_options SET option_value='https://$SITE_DOMAIN/staging' WHERE option_name='siteurl'"; mysql --execute="UPDATE ${DB_NAME}.dev_options SET option_value='https://$SITE_DOMAIN/dev' WHERE option_name='home'"; mysql --execute="UPDATE ${DB_NAME}.dev_options SET option_value='https://$SITE_DOMAIN/dev' WHERE option_name='siteurl'"; ## cleanup tmp files ## rm /var/www/meta/staging*.sql* rm /tmp/staging*.sql* #################################################################################################### #### SS-Sync-Staging: Configure Staging Site WP-Config File (Same As SS-Install) ################### #################################################################################################### ## MODULE VERSION: WP-Config Build # ## retrieve latest wp-config boilerplate ## wget -O /var/www/html/staging/wp-config.php http://mirrors.slickstack.io/wordpress/wp-config-staging.txt ###### WP Multisite settings ######## ## set multisite subdomains ## if [[ -z "$WP_MULTISITE_SUBDOMAINS" ]]; then sed -i "s/@WP_MULTISITE_SUBDOMAINS/true/g" /var/www/html/staging/wp-config.php else sed -i "s/@WP_MULTISITE_SUBDOMAINS/${WP_MULTISITE_SUBDOMAINS}/g" /var/www/html/staging/wp-config.php fi ## set multisite ## if [[ -z "$WP_MULTISITE" ]]; then sed -i "s/@WP_MULTISITE/false/g" /var/www/html/staging/wp-config.php else sed -i "s/@WP_MULTISITE/${WP_MULTISITE}/g" /var/www/html/staging/wp-config.php fi ## multisite ## if [[ "$WP_MULTISITE" == "true" ]]; then sed -i "s/@WP_MULTISITE/true/g" /var/www/html/staging/wp-config.php else sed -i "s/@WP_MULTISITE/false/g" /var/www/html/staging/wp-config.php fi ####### other WP Config settings ########## ## replace database placeholders ## sed -i "s/@DB_NAME/${DB_NAME}/g" /var/www/html/staging/wp-config.php sed -i "s/@DB_USER/${DB_USER}/g" /var/www/html/staging/wp-config.php sed -i "s/@DB_PASSWORD/${DB_PASSWORD}/g" /var/www/html/staging/wp-config.php sed -i "s/@DB_HOST/${DB_HOST}/g" /var/www/html/staging/wp-config.php sed -i "s/@DB_CHARSET/${DB_CHARSET}/g" /var/www/html/staging/wp-config.php sed -i "s/@DB_COLLATE/${DB_COLLATE}/g" /var/www/html/staging/wp-config.php sed -i "s/@DB_PREFIX/staging_${DB_PREFIX}/g" /var/www/html/staging/wp-config.php ## disable object cache (staging) ## sed -i "s/@OBJECT_CACHE/false/g" /var/www/html/staging/wp-config.php ## set language ## if [[ -z "$WP_LANG" ]]; then sed -i "s/@WP_LANG/en-US/g" /var/www/html/staging/wp-config.php else sed -i "s/@WP_LANG/${WP_LANG}/g" /var/www/html/staging/wp-config.php fi ## replace domain placeholders ## sed -i "s#@SITE_DOMAIN#${SITE_DOMAIN}#g" /var/www/html/staging/wp-config.php sed -i "s/@SITE_TLD/${SITE_TLD}/g" /var/www/html/staging/wp-config.php ## replace SFTP Details placeholders ## sed -i "s/@SFTP_USER/${SFTP_USER}/g" /var/www/html/staging/wp-config.php sed -i "s/@SFTP_PASSWORD/${SFTP_PASSWORD}/g" /var/www/html/staging/wp-config.php if [[ -z "$SSH_PORT" ]]; then sed -i "s/@SSH_PORT/6969/g" /var/www/html/staging/wp-config.php else sed -i "s/@SSH_PORT/${SSH_PORT}/g" /var/www/html/staging/wp-config.php fi ## replace CloudFlare placeholders ## sed -i "s/@CLOUDFLARE_API_KEY/${CLOUDFLARE_API_KEY}/g" /var/www/html/staging/wp-config.php sed -i "s/@CLOUDFLARE_API_EMAIL/${CLOUDFLARE_API_EMAIL}/g" /var/www/html/staging/wp-config.php ## CloudFlare DNS widget ## if [[ -z "$CLOUDFLARE_WIDGET_DNS" ]]; then sed -i "s/@CLOUDFLARE_WIDGET_DNS/true/g" /var/www/html/staging/wp-config.php else sed -i "s/@CLOUDFLARE_WIDGET_DNS/${CLOUDFLARE_WIDGET_DNS}/g" /var/www/html/staging/wp-config.php fi ## lookup salt keys from production wp-config ## PROD_AUTH_KEY=$(grep "'AUTH_KEY'" /var/www/html/wp-config.php) PROD_SECURE_AUTH_KEY=$(grep "'SECURE_AUTH_KEY'" /var/www/html/wp-config.php) PROD_LOGGED_IN_KEY=$(grep "'LOGGED_IN_KEY'" /var/www/html/wp-config.php) PROD_NONCE_KEY=$(grep "'NONCE_KEY'" /var/www/html/wp-config.php) PROD_AUTH_SALT=$(grep "'AUTH_SALT'" /var/www/html/wp-config.php) PROD_SECURE_AUTH_SALT=$(grep "'SECURE_AUTH_SALT'" /var/www/html/wp-config.php) PROD_LOGGED_IN_SALT=$(grep "'LOGGED_IN_SALT'" /var/www/html/wp-config.php) PROD_NONCE_SALT=$(grep "'NONCE_SALT'" /var/www/html/wp-config.php) ## generate unique salts ## sed -i "s/@AUTHKEY/$(openssl rand -hex 48)/g" /var/www/html/staging/wp-config.php sed -i "s/@SECUREAUTHKEY/$(openssl rand -hex 48)/g" /var/www/html/staging/wp-config.php sed -i "s/@LOGGEDINKEY/$(openssl rand -hex 48)/g" /var/www/html/staging/wp-config.php sed -i "s/@NONCEKEY/$(openssl rand -hex 48)/g" /var/www/html/staging/wp-config.php sed -i "s/@AUTHSALT/$(openssl rand -hex 48)/g" /var/www/html/staging/wp-config.php sed -i "s/@SECUREAUTHSALT/$(openssl rand -hex 48)/g" /var/www/html/staging/wp-config.php sed -i "s/@LOGGEDINSALT/$(openssl rand -hex 48)/g" /var/www/html/staging/wp-config.php sed -i "s/@NONCESALT/$(openssl rand -hex 48)/g" /var/www/html/staging/wp-config.php ## Replace Placeholders: Debug and Dev/staging server ## sed -i "s/@WP_DEBUG/true/g" /var/www/html/staging/wp-config.php sed -i "s/@WP_LOCAL_DEV/false/g" /var/www/html/staging/wp-config.php ## core auto updates ## if [[ -z "$WP_AUTO_UPDATE_CORE" ]]; then sed -i "s/@WP_AUTO_UPDATE_CORE/minor/g" /var/www/html/staging/wp-config.php else sed -i "s/@WP_AUTO_UPDATE_CORE/${WP_AUTO_UPDATE_CORE}/g" /var/www/html/staging/wp-config.php fi ## autosave (drafts) ## if [[ -z "$WP_AUTOSAVE_INTERVAL" ]]; then sed -i "s/@WP_AUTOSAVE_INTERVAL/60/g" /var/www/html/staging/wp-config.php else sed -i "s/@WP_AUTOSAVE_INTERVAL/${WP_AUTOSAVE_INTERVAL}/g" /var/www/html/staging/wp-config.php fi ## revisions ## if [[ -z "$WP_POST_REVISIONS" ]]; then sed -i "s/@WP_POST_REVISIONS/5/g" /var/www/html/staging/wp-config.php else sed -i "s/@WP_POST_REVISIONS/${WP_POST_REVISIONS}/g" /var/www/html/staging/wp-config.php fi ## block external requests ## if [[ -z "$WP_HTTP_BLOCK_EXTERNAL" ]]; then sed -i "s/@WP_HTTP_BLOCK_EXTERNAL/false/g" /var/www/html/staging/wp-config.php else sed -i "s/@WP_HTTP_BLOCK_EXTERNAL/${WP_HTTP_BLOCK_EXTERNAL}/g" /var/www/html/staging/wp-config.php fi ## allowed hosts ## if [[ -z "$WP_ACCESSIBLE_HOSTS" ]]; then sed -i "s/@WP_ACCESSIBLE_HOSTS/api.wordpress.org/g" /var/www/html/staging/wp-config.php else sed -i "s/@WP_ACCESSIBLE_HOSTS/${WP_ACCESSIBLE_HOSTS}/g" /var/www/html/staging/wp-config.php fi ## file edits ## sed -i "s/@WP_DISALLOW_FILE_EDIT/false/g" /var/www/html/staging/wp-config.php ## file mods ## sed -i "s/@WP_DISALLOW_FILE_MODS/false/g" /var/www/html/staging/wp-config.php ## file uploads ## if [[ -z "$WP_ALLOW_UNFILTERED_UPLOADS" ]]; then sed -i "s/@WP_ALLOW_UNFILTERED_UPLOADS/true/g" /var/www/html/staging/wp-config.php else sed -i "s/@WP_ALLOW_UNFILTERED_UPLOADS/${WP_ALLOW_UNFILTERED_UPLOADS}/g" /var/www/html/staging/wp-config.php fi #################################################################################################### #### SS-Sync-Staging: Install WordPress MU Plugins ################################################# #################################################################################################### ## run ss-muplugs ## source /var/www/ss-muplugs #################################################################################################### #### SS-Sync-Staging: Reset Permissions (WordPress Core + WordPress Config) ######################## #################################################################################################### ## run ss-perms-wordpress-core ## source /var/www/ss-perms-wordpress-core ## run ss-perms-wordpress-config ## source /var/www/ss-perms-wordpress-config ## end parent if ## fi #################################################################################################### #### SS-Sync-Staging: Touch Timestamp File (End Of Script) ######################################### #################################################################################################### ## this is a dummy timestamp file that will remember the last time this script was run ## ## it can be useful for developer reference and is sometimes used by SlickStack ## ## script timestamp ## touch /var/www/meta/.timestamp-ss-sync-staging #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: https://community.centminmod.com/threads/wp-engine-type-production-staging-file-and-db-sync.19720/ ## Ref: https://softwareengineering.stackexchange.com/questions/117945/staging-environment-vs-production-environment ## Ref: https://www.thegeekstuff.com/2011/01/rsync-exclude-files-and-folders/ ## Ref: https://stackoverflow.com/questions/2466101/how-i-can-change-prefixes-in-all-tables-in-my-mysql-db ## Ref: https://stackoverflow.com/questions/55055130/mysql-copy-tables-with-specific-prefix-between-databases ## Ref: https://stackoverflow.com/questions/3280006/duplicating-a-mysql-table-indices-and-data ## Ref: https://tableplus.com/blog/2018/11/how-to-duplicate-a-table-in-mysql.html ## Ref: https://electrictoolbox.com/copy-table-mysql-create-table-like/ ## Ref: https://guides.wp-bullet.com/advanced-wordpress-search-replace-database-with-linux-using-sed/ ## Ref: https://stackoverflow.com/questions/1917021/mysqldump-table-names-prefix ## Ref: https://dba.stackexchange.com/questions/8869/restore-mysql-database-with-different-name ## Ref: https://linuxize.com/post/how-to-back-up-and-restore-mysql-databases-with-mysqldump/ ## Ref: https://stackoverflow.com/questions/12677037/how-to-import-a-mysql-dump-from-command-line-with-overwrite ## Ref: https://dba.stackexchange.com/questions/35847/mysqldump-flush-privileges-option ## Ref: https://stackoverflow.com/questions/11263018/mysql-ignore-errors-when-importing ## Ref: https://askubuntu.com/questions/76808/how-do-i-use-variables-in-a-sed-command ## Ref: https://stackoverflow.com/questions/54460445/sed-permission-denied-on-temporary-file ## Ref: https://www.unix.com/shell-programming-and-scripting/31583-wildcards-sed.html ## Ref: https://stackoverflow.com/questions/9189120/using-sed-with-wildcard ## Ref: http://helpdoco.com/Linux-Unix/sed-cannot-rename-permission-denied.htm ## Ref: https://precisionsec.com/changing-the-wordpress-site-url-using-the-mysql-command-line/ ## Ref: https://stackoverflow.com/questions/20033648/how-to-run-mysql-command-on-bash ## Ref: https://polevaultweb.com/2014/03/5-ways-synchronise-wordpress-uploads-across-environments/ ## Ref: https://blog.room34.com/archives/5091/wheres-the-option-to-change-the-uploads-path-in-wordpress-3-5/ ## Ref: https://premium.wpmudev.org/blog/sync-staging-live-sites-wordpress/ ## Ref: https://poststatus.com/functions-constants-referencing-wordpress-content-uploads-plugin-directories/ ## Ref: https://phoenixnap.com/kb/rsync-exclude-files-and-directories ## Ref: http://qdosmsq.dunbar-it.co.uk/blog/2013/02/rsync-to-slash-or-not-to-slash/ ## Ref: http://lucasb.eyer.be/snips/rsync-skipping-directory.html ## Ref: https://stackoverflow.com/questions/1583219/how-to-do-a-recursive-find-replace-of-a-string-with-awk-or-sed ## Ref: https://www.jamesnimmo.co.nz/2020/04/16/create-a-dev-copy-of-your-wordpress-site-with-wordops/ ## Ref: https://serverfault.com/questions/105206/rsync-exclude-files-that-are-over-a-certain-size ## Ref: https://man7.org/linux/man-pages/man1/rsync.1.html ## Ref: https://stackoverflow.com/questions/9952000/using-rsync-include-and-exclude-options-to-include-directory-and-file-by-pattern ## Ref: https://askubuntu.com/questions/476041/how-do-i-make-rsync-delete-files-that-have-been-deleted-from-the-source-folder ## Ref: https://www.cyberciti.biz/faq/linux-bash-delete-all-files-in-directory-except-few/ ## Ref: https://superuser.com/questions/783622/how-to-make-grep-command-return-entire-matching-line ## Ref: https://stackoverflow.com/questions/22319345/copy-lines-containing-word-from-one-file-to-another-file-in-linux ## Ref: https://stackoverflow.com/questions/6749128/store-output-of-sed-into-a-variable ## Ref: https://wordpress.org/support/topic/fatal-error-call-to-undefined-function-wp-in-home-content-06-9767406-html-wp/ ## Ref: https://stackoverflow.com/questions/11245144/replace-whole-line-containing-a-string-using-sed/36195381#36195381 ## Ref: https://www.gnu.org/software/sed/manual/html_node/sed-commands-list.html ## Ref: https://www.geeksforgeeks.org/sed-command-in-linux-unix-with-examples/ ## Ref: https://docs.woocommerce.com/document/subscriptions-handles-staging-sites/ ## Ref: https://linuxize.com/post/bash-if-else-statement/ ## Ref: https://wpengine.com/support/wordpress-serialized-data/ ## Ref: https://wp-staging.com/serialized-data-wordpress-important/ ## Ref: https://stackoverflow.com/questions/15138893/fix-serialized-data-broken-due-to-editing-mysql-database-in-a-text-editor ## Ref: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ ## Ref: https://wordpress.stackexchange.com/questions/9076/why-is-my-database-import-losing-text-widget-data ## Ref: https://gist.github.com/gmartellino/4692252 ## SS_EOF