Skip to content

Instantly share code, notes, and snippets.

@takeru
Created January 21, 2010 04:28
Show Gist options
  • Save takeru/282578 to your computer and use it in GitHub Desktop.
Save takeru/282578 to your computer and use it in GitHub Desktop.
require "rubygems"
require "yaml"
require "pp"
backup_dir = "./backup_gems"
Dir.mkdir(backup_dir) unless File.exist?(backup_dir)
GEM_CACHE_PATH = "/opt/local/lib/ruby/gems/1.8/cache"
Dir["#{GEM_CACHE_PATH}/*"].select{|name| name=~/appengine/ }.each do |name|
spec = Gem::Specification.from_yaml(`gem spec #{name}`)
timestamp = spec.date.strftime("%Y_%m%d_%H%M%S_%Z")
basename = File.basename(name)
sha1sum = `shasum -a 1 -b #{name}`[/^(\S{40})/, 1]
puts "#{name} #{sha1sum} #{timestamp}"
backup_name = "#{basename}-#{timestamp}-#{sha1sum}"
backup_path = "#{backup_dir}/#{backup_name}"
unless File.exist?(backup_path)
puts " => copying. " + `cp -v #{name} #{backup_path}`
else
puts " => exist."
end
end
% ruby backup_appengine_gems.rb
/opt/local/lib/ruby/gems/1.8/cache/appengine-apis-0.0.12.gem 97f69e99a2b77a291832c1f1b1b5dbaf6e14bbd8 2009_1221_170000_JST
=> exist.
/opt/local/lib/ruby/gems/1.8/cache/appengine-jruby-jars-0.0.6.gem 3a8bb13e88df0e4eb90b37f4d55acf0b8a6d4cd3 2009_1221_170000_JST
=> exist.
/opt/local/lib/ruby/gems/1.8/cache/appengine-jruby-jars-0.0.7.pre.gem b242e49425d561e7ec5bbe03d8f8b2a32cb0de12 2009_1215_170000_JST
=> exist.
/opt/local/lib/ruby/gems/1.8/cache/appengine-rack-0.0.6.gem 23adff1965d050c78192d15f8f6ad03cf7295dd8 2009_1221_170000_JST
=> exist.
/opt/local/lib/ruby/gems/1.8/cache/appengine-sdk-1.3.0.gem aeffb37726a1f3140ce7547bce2c69ea22fc2661 2009_1221_170000_JST
=> exist.
/opt/local/lib/ruby/gems/1.8/cache/appengine-tools-0.0.8.gem a7d2ff42b409f245912db801cd69aec5bda30d1b 2010_0120_170000_JST
=> exist.
/opt/local/lib/ruby/gems/1.8/cache/appengine-tools-0.0.9.gem c0eb2edf09a3a65373765a30ed0a8aad6fe77f16 2010_0121_170000_JST
=> copying. /opt/local/lib/ruby/gems/1.8/cache/appengine-tools-0.0.9.gem -> ./backup_gems/appengine-tools-0.0.9.gem-2010_0121_170000_JST-c0eb2edf09a3a65373765a30ed0a8aad6fe77f16
/opt/local/lib/ruby/gems/1.8/cache/google-appengine-0.0.9.gem 10b8623050dbdb7ee89444bd8a8e105a3f0ce255 2010_0121_170000_JST
=> copying. /opt/local/lib/ruby/gems/1.8/cache/google-appengine-0.0.9.gem -> ./backup_gems/google-appengine-0.0.9.gem-2010_0121_170000_JST-10b8623050dbdb7ee89444bd8a8e105a3f0ce255
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment