Previous Next

Backup Rake Tasks · 273 days ago

Rsync is awesome, but I kept forgetting the options whenever I wanted to backup my laptop.

Rake to the rescue!

rakefile.rb:

require 'rake'
desc 'rake backup:hoard'
task :default => 'backup:hoard'
namespace :backup do

desc 'Backup /Users/ dir to the Hoard disk' task :hoard => "/Volumes/Hoard" do rsync '/Users/Shared/Installed', '/Volumes/Hoard/Software/' and rm_rf Dir['/Users/Shared/Installed/*'] rsync '/Users', '/Volumes/Hoard/', :options=>'-avuPE --delete' end end def rsync *args options = args.last.is_a?(Hash) ? args.pop : {} options = {:options=>"-avuPE", :background=>false}.merge(options) cmds = ['sudo rsync', options[:options]] + args cmds << ' > /dev/null &' if options[:background] puts( cmd = cmds.join(' ') ) IO.popen(cmd) do |f| while o = f.gets puts o end end end

I also made some tasks for syncing my iTunes Library on my old G4 and my Ubuntu machines, but I won’t bore you with those.

The little => "/Volumes/Hoard" makes sure that my Hoard disk is mounted. If it isn’t mounted you get an error like Don't know how to build task '/Volumes/Hoard'. Rsync uses \r to do a progress on each file, but the f.gets in the IO.popen’s block doesn’t show it. There is probably a way to do this but this is good enough for me :)

Comments