Cleaning up your local Drupal installations for the New Year

If you're like me, your development and staging servers get larger and larger as time moves on.  The end of the year break is the perfect time to get organized, archive projects that are no longer needed, and set up some settings configurations that will help keep next year under control.  

Clean up Backup and Migrate Backups

In Drupal 7, Backup and Migrate has some great drush commands that I never knew existed until recently. These commands can help you quickly make a backup, and/or inventory the backups you have on your system.

/* To get a list of destinations */
drush bam-destinations

/* To get a list of backups */
drush bam-backups [destination]

/* To get a list of profiles */
drush bam-profiles

/* Make a Backup */
/* bam-backup or alias bb */
drush bb [db/files] [manual/scheduled] [settings-profile]

Make a Bash Script

If you've amassed a lot of backup files like I have the tendency to do, here is a method I developed to systematically delete these old, unwanted backups using a simple bash script. This will work on a Mac and should translate to working on Linux servers.

Create a file called rmbm and save it to: /Users/yourname/bin/. Add the following code:

# This script asks for the Backup Destination and Filename, then deletes it
# Change the last line to where your /private/backup_migrate/ resides if needed.
echo "Enter the Destination and the Filename to delete the Backup."
read -p 'Destination: ' destvar
read -p 'Filename: ' filevar
rm sites/default/files/private/backup_migrate/$destvar/$filevar

Make the file executable:

chmod +x /Users/yourname/bin/rmbm

/* Verify by typing: */
which rmbm

/* The output should be: */

Now that the script file is created, My process is to:

drush bam-backups
/* and enter the files you want to delete */
/* Repeat */

Clean up Images

Images also take up a lot of space on your dev and staging environments. Let's get rid of them, and use the Stage File Proxy module to hotlink to the images moving forward.  If you don't have Stage File Proxy installed, checkout my earlier blog post.

/* To delete all image presets */
drush image-flush --all

Open your settings.php or local.settings.php file and add the following settings:

/* Stage File Proxy Settings */
$conf['stage_file_proxy_origin'] = ''; /* Enter the URL of your production site */
$conf['stage_file_proxy_hotlink'] = TRUE;

In Conclusion

Besides that, take a look at the sites you have installed locally and on your staging server. Are there any that you can delete or archive?  Now would be a great time to do it.

I hope you all have a great and productive 2016!