4

Can drush take piping commands for a multisite command using an alias?

I'm trying to setup a simple refresh function from my prod to dev/staging. Any pointers or tips would be welcome. just started learning this stuff.

drush $prodalias sql-dump --gzip >/tmp/$site.sql.gz gunzip /tmp/$site.sql.gz | drush $devalias sqlc 

2 Answers 2

1

I write bash/shell scripts involving Drush all the time. If it's just the variables you're interested in, that has nothing to do with Drush and works fantastically. As for piping, I i'm not too sure what all is supported.

For bash to interpret your variables, you just need to wrap them in quotes.

Example:

#!/bin/bash source=$1 dest=$2 # Check if we have both a source and a destination. if [ -z "$dest"]; then # Looks like at least one of our parameters are missing, notify and exit. echo "A source and destination Drush alias is required." exit 1 fi drush sql-sync "$source" "$dest" 

Usage:

./my-sync-script.sh @alias.prod @alias.dev 
1

It should be allowed to use piping in drush aliases as this feature was added recently by improving escaping options for core-exec.

So you have to upgrade your drush to the recent version (7.x).

See: Are pipes allowed in shell aliases?


If you prefer to use script, here is one which I'm usually using:

#!/bin/sh # pull-db.sh # Script to pull the database from remote to local environment. [ -z "$1" ] && { echo "Usage: $0 @remote (args)"; exit 1; } SRC="$1" shift drush $SRC sql-dump | drush $* sql-cli 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.