Sometimes you have config, such as webform or views, being changed in a remote environment. When you don't have a quick way to capture it, it can be frustrating for the developer.
Ideally, the best way to capture config will be something like drush @remote config-export
, but this is not possible if you don't have ssh access to the remote environment. Another option is pulling down a database dump, importing the database and exporting the config locally.
If these options are not available, or least not available in a timely way, then you might visit /admin/config/development/configuration/full/export
in the Drupal admin. You can press Export, and download a tar.gz file, and place it locally. For the script below your user account will need access to this admin page.
Today we look at the last option as a script, without getting too technical about it. Basically we need to:
- Log in with our Drupal password (not stored anywhere)
- Save the session cookie
- Load the config export page (your user needs access)
- Save and extract the zip file in the config directory locally
- ... Ready to commit in the Git repo
This script is as-is. If you use this script you should understand or modify it to suit your own circumstances. Although it's unlikely to do any damage that a git checkout config
can't fix. Some notes:
- Assumes config is in
./config/default
relative to where the script is run from (eg the root of the repo). - Doesn't really do any error handling.
- Assumes the login form is default at
/user/login
. - Hard-codes the DOMAIN setting which you'd need to edit.
- Assumes your local config is committed and a
git diff config
will show new changes. - Tested on OSX, not sure if this would work on other platforms.
If you improve this script, please share!
#!/bin/bash
echo "What is your website user name:"
read USER
echo "What is your website password:"
read -s PASS
POST="name=${USER}&pass=${PASS}&form_id=user_login_form&op=Log%20in"
DOMAIN="https://remote-site.com"
# If your site is protected by shield.
# --http-user somename \
# --http-password somepass \
wget \
--keep-session-cookies \
--save-cookies /tmp/some-cookies.txt \
--post-data ${POST} \
--delete-after \
${DOMAIN}/user/login
wget -O ./config/default/exported-config.tar.gz \
--load-cookies /tmp/some-cookies.txt \
${DOMAIN}/admin/config/development/configuration/full/export-download
rm -Rf ./config/default/*.yml
tar xzf ./config/default/exported-config.tar.gz -C ./config/default
rm ./config/default/exported-config.tar.gz
git diff config
echo "Done. Check the output of 'git diff config' above and commit once you're happy."
Add new comment