If I have config that's out of sync on production, I may want to export it without copying down the database, or I may have environment-specific config that interferes with exporting config from the local environment. Is there a way to export config from a remote environment locally?
1 Answer
Edit: Turns out drush has a config-pull
command to handle exactly this:
https://drushcommands.com/drush-8x/config/config-pull/
However, it doesn't work with config_ignore as far as I can tell.
The original answer for posterity:
I've found that this bash command does the trick (on Mac OS X):
yes n | drush @site.env cim sync --preview=diff | \
sed -E 's/([\-]{3} ).*(\/.*.yml)/\1a\/config\/sync\2/' | \
sed -E 's/([\+]{3} ).*(\/.*.yml)/\1b\/config\/sync\2/' > cim.patch && \
interdiff -q cim.patch /dev/null > cex.patch && \
git apply cex.patch && \
rm cex.patch cim.patch
We use the preview argument of drush config-import (passing in 'n' when it prompts to import), clean up path names with sed, reverse the patch from import to export, and finally apply it and clean up. Note that you have to be on the same git branch as production.
With drush 9, the output and yes
functionality changes a little, so you can instead use:
drush @site.env cim sync --no --preview=diff 2>/dev/null | \
sed -E 's/([\-]{3} ).*(\/.*.yml)/\1a\/config\/sync\2/' | \
sed -E 's/([\+]{3} ).*(\/.*.yml)/\1b\/config\/sync\2/' > cim.patch && \
interdiff -q cim.patch /dev/null > cex.patch && \
git apply cex.patch && \
rm cex.patch cim.patch
-
1
cpull
doesn't export active config, it just rsync's the staged config from the @source directory. Commented Oct 22, 2021 at 20:10