Giter VIP home page Giter VIP logo

trellis-sync's Introduction

Trellis Sync

This is a repository for the Trellis Database and Uploads Folder Synchronisation scripts and WP CLI Aliases. Two scripts have been added here. The database backup script or sync-db-from-prod.sh to synch the production database with the one on the local server and sync-all.sh to synchronize both the database and uploads folder.

File location and changes

Make sure you change the domain in both the shell script and your wp-cli.yaml files. For using the sync-db-from-prod.sh script it should be placed in the Wordpress root. For using the sync-all.sh it is setup to be run from site/scripts/. Or at least it is setup from a subdirectory inside your WordPress root or site folder.

Database Sync (Production -> Dev)

The Database sync script sync-db-from-prod.sh and aliases setup has been created by Raquelle. See Roots Blog post. It is set up to sync the database from production and update the one on development or on the local server.

Sync All

The Sync All script sync-all.sh which can be used to synchronize the uploads folder and database has been created by Ben Word and thread post where he added can be found at Roots Discourse . It will work for synching to and from production to local and to and from staging to local. It is located in the scripts folder, but will work from any sub directory in your WordPress root which often tends to be site witha standard Trellis setup with Bedrock.

Installation

Installation can be done using composer require trellis-sync/trellis-sync. This is still not fully tested so do make a backup first!

trellis-sync's People

Contributors

frederikvdbe avatar jasperf avatar strarsis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

trellis-sync's Issues

/usr/bin/env: ‘mysqldump’: No such file or directory

Running the script it has issues using mysqldump on my MacOs Sierra though running it from the terminal using mysqldump works just fine. Here is what I get

./sync-db-from-prod.sh
Do you solemnly swear that you have had fewer than 2 alcoholic beverages in the last hour and that you would really like to reset your development database and pull the latest from production? [y/N] y
Success: Database reset.
/usr/bin/env: ‘mysqldump’: No such file or directory
Success: Imported from 'sql-dump-production.sql'.
Error: The site you have requested is not installed.
Run `wp core install`.

Use config from wp-cli.yml

The wp cli aliases are already defined in wp-cli.yml - it would reduce the amount of config and
the necessity keeping it in sync when trellis-sync also uses the config in wp-cli.yml.

Add as WP CLI package

Wouldn't it be a nice addition to have this tool as a WP CLI package,
also installable using wp package install ?

Add -L switch

The -L switch let rsync follow symlinks/Junctions (in WSL/Bash on Windows).
This can be helpful - wouldn't it make sense to add this switch to the script?

Error when running sync-all.sh

Running the script returns:

scripts/sync-all.sh: 25: scripts/sync-all.sh: Syntax error: "(" unexpected (expecting "then")

"The source and destination cannot both be remote."

Transferring the database dump and replacements work well,
but transferring the uploads/ folder between the two servers results in this error message:

[...]
Success: Made 16 replacements.
The source and destination cannot both be remote.
rsync error: syntax or usage error (code 1) at main.c(1279) [Receiver=3.1.1]

Backup?

This script works really nice for transferring data between WordPress installations.
Is there also an example for using this script for backing up to tar/gzip,
ideally incrementally (important for the uploads files), with date/time stamps?
I plan to run the script in regular intervals for automated site backups
(from production site which holds the authoritative data).

Multisite compatability and some tweaks...

As the Wordpress CLI page suggests in the examples of a way to have multisite compatibility. I tweaked the sync-all.sh script for this and to also ask if the uploads folder should update. Also shortened the options names 👍
It does not seem to be working... however 👎
This is what I have so far:

#!/bin/bash

DEVDIR="web/app/uploads/"
DEVSITE="https://example.dev"

PRODDIR="[email protected]:/srv/www/example.com/current/web/app/uploads"
PRODSITE="https://example.com"

STAGDIR="[email protected]:/srv/www/example.com/current/web/app/uploads"
STAGSITE="https://staging.example.com"

FROM=$1
TO=$2

case "$1-$2" in
  dev-prod) DIR="up";  FROMSITE=$DEVSITE;  FROMDIR=$DEVDIR;  TOSITE=$PRODSITE; TODIR=$PRODDIR; ;;
  dev-stage)    DIR="up"   FROMSITE=$DEVSITE;  FROMDIR=$DEVDIR;  TOSITE=$STAGSITE; TODIR=$STAGDIR; ;;
  prod-dev) DIR="down" FROMSITE=$PRODSITE; FROMDIR=$PRODDIR; TOSITE=$DEVSITE;  TODIR=$DEVDIR; ;;
  stage-dev)    DIR="down" FROMSITE=$STAGSITE; FROMDIR=$STAGDIR; TOSITE=$DEVSITE;  TODIR=$DEVDIR; ;;
  *) echo "usage: $0 dev prod | dev stage | prod dev | prod stage" && exit 1 ;;
esac

read -r -p "Reset the $TO database and sync $DIR from $FROM? [y/N] " response
read -r -p "Sync the uploads folder? [y/N] " uploads

cd ../ &&
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
  wp "@$TO" db export $TO.sql
  wp "@$TO" db reset --yes
  wp "@$FROM" db export $FROM.sql
  if $(wp "@$FROM" core is-installed --network); then
    echo "multisite"
    wp "@$FROM" search-replace '$FROMSITE' '$TOSITE' --recurse-objects --skip-columns=guid --network --export | wp "@$TO" db import -
  else
    wp "@$FROM" search-replace '$FROMSITE' '$TOSITE' --recurse-objects --skip-columns=guid --export | wp "@$TO" db import -
  fi
fi
if [[ "$uploads" =~ ^([yY][eE][sS]|[yY])$ ]]; then
  rsync -az --progress "$FROMDIR" "$TODIR"
fi

When I use this to sync from dev to stage, I get a redirect loop when I try to load the staging page. If I, however, just do a manual search and replace of the raw sql (playing with fire, I know) file it seems to work.

error: ssh configuration...cannot connect

Error when running sync-all.sh

[user@host scripts]$ bash sync-all.sh dev stage
Reset the stage database and sync up from dev? [y/N] y
Sync the uploads folder? [y/N] y
Success: Exported to 'stage-backup.sql'.
Success: Database reset.
Error: Cannot connect over SSH using provided configuration.
sending incremental file list

Result
Strangely the demo file I placed in the /web/app/uploads folder did successfully get uploaded to the stage environment. But when I removed the demo file and tried to run that same command again, the demo file remained in the stage environment as if it was not updating. It can send the file but cannot delete the file so it doesn't seem to be syncing.

Debug attempts:
I also checked the user 'web' and was able to successfully ssh into my remote server.

.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.