Back Up Middleman Source to Dropbox Automatically on Build

Published: 2013-10-11 14:28 EDT

Updated: 2016-09-22

Yes, I have my site source under version control. In order to have a private repository for free I’m using BitBucket to host my source repository. I then publish the build to github pages. In any case, I still like knowing that I have a backup of my site content somewhere else. I also wanted to play around with custom extensions. Here’s a task I use to backup the source of my site to Dropbox after each build.

class MoveSourceToDropbox < Middleman::Extension
  def initialize(app, options_hash={}, &block)
    super
    app.after_build do |builder|
      builder.thor.run('rm -r ~/Dropbox/prelim_inventory/*')
      builder.thor.run('cp -r ./source/* ~/Dropbox/prelim_inventory/.')
    end
  end
end
::Middleman::Extensions.register(:move_source_to_dropbox, MoveSourceToDropbox)
activate :move_source_to_dropbox

Nice and easy to use callbacks like this to extend the framework. Thank you Middleman!