Drupal Site Reset BASH Script
I'm experimenting with Drupal 8 and some its new features like migration and configuration management. A reset script is a convenient timesaver and many people have shared their techniques for doing so. Having benefited from other's generosity I wanted to return the favour by sharing my current work-in-progress.
This script:
- Leaves the codebase as-is
- Deletes and reinstalls the database
- Deletes the 'files' directory
- Deletes the specified configuration management directory
- Enables additional modules, as required
- Deletes settings.php and allows Drupal install to recreate
- Updates the new settings.php $config_directories['sync'] entry
- Adds a settings-migrate.php include to settings.php
I call the script via Drush with an entry in drushrc.php:
$options['shell-aliases']['428-reset'] = '!sh /Users/dale/.drush/sha-scripts/g428-reset.sh';
The script is evolving as I learn more about Drupal 8 and refine my workflow. Comments and suggestions are welcome.
drupal-reset.sh:
#!/bin/bash<br><br># Reinstall a Drupal instance to reset it back to a know state.<br># A file base and Drush alias must already be configured.<br><br>DRUSH8='/Users/dale/bin/drush8/vendor/bin/drush'<br>DRUPALDIR='/Users/dale/Sites/group428'<br>CONFIGDIR='sites/default/group42config/sync'<br>DRUSHID='@g428'<br>SITE_NAME='Group 428'<br>ACCOUNT='admin'<br>PASS='staring-password'<br>EMAIL='no-reply@group42.ca'<br>DB_URL='mysql://group428:group428@localhost/group428'<br><br><br># Nuke the database<br>$DRUSH8 $DRUSHID sql-drop --yes<br><br># Nuke the filebase<br>echo "Resetting files"<br>chmod -R u+w $DRUPALDIR/*<br>rm $DRUPALDIR/sites/default/settings.php<br>rm -r $DRUPALDIR/sites/default/files<br>rm -r $DRUPALDIR/$CONFIGDIR<br><br># Fresh Drupal install<br>cd $DRUPALDIR<br>$DRUSH8 site-install standard --db-url=$DB_URL --site-name=$SITE_NAME --account-name=$ACCOUNT --account-pass=$PASS --account-mail=$EMAIL --yes<br><br># Base configuration<br>$DRUSH8 $DRUSHID en admin_toolbar,admin_toolbar_tools --yes<br><br># Allow upcoming changes to settings.php<br>chmod u+w $DRUPALDIR/sites/default<br>chmod u+w $DRUPALDIR/sites/default/settings.php<br><br># Configuration Management<br>sed -i '' "/config\_directories\['sync'\]/d" $DRUPALDIR/sites/default/settings.php<br>echo "\$config_directories['sync'] = '$CONFIGDIR';" >> $DRUPALDIR/sites/default/settings.php<br><br># Migrate<br>echo "\ninclude 'settings-migrate.php';" >> $DRUPALDIR/sites/default/settings.php<br>$DRUSH8 $DRUSHID en migrate,migrate_drupal,migrate_plus,migrate_tools,migrate_upgrade --yes<br><br># Login<br>$DRUSH8 $DRUSHID uli
Tagged:
AttachmentSize Drupal Reset BASH Script1.43 KB