+puts 'RBot Registry Backup/Restore/Migrate'
+puts '[%s]' % ['Ruby: ' + RUBY_VERSION,
+ 'DBM: ' + (DBM::VERSION rescue '-'),
+ 'BDB: ' + (BDB::VERSION rescue '-'),
+ 'TokyoCabinet: ' + (TokyoCabinet::VERSION rescue '-'),
+ 'Daybreak: ' + (Daybreak::VERSION rescue '-'),
+ 'SQLite: ' + (SQLite3::VERSION rescue '-'),
+ ].join(' | ')
+
+require 'date'
+require 'optparse'
+
+TYPES = [:bdb, :tc, :dbm, :daybreak, :sqlite]
+options = {
+ :profile => '~/.rbot',
+ :registry => nil,
+ :dbfile => './%s.rbot' % DateTime.now.strftime('backup_%Y-%m-%d_%H%M%S'),
+ :type => nil
+}
+opt_parser = OptionParser.new do |opt|
+ opt.banner = 'Usage: rbotdb COMMAND [OPTIONS]'
+ opt.separator ''
+ opt.separator 'Commands:'
+ opt.separator ' backup: store rbot registry platform-independently in a file.'
+ opt.separator ' restore: restore rbot registry from such a file.'
+ opt.separator ''
+ opt.separator 'Options:'
+
+ opt.on('-t', '--type TYPE', TYPES, 'format to backup/restore. Values: %s.' % [TYPES.join(', ')]) do |type|
+ options[:type] = type
+ end
+
+ opt.on('-p', '--profile [PROFILE]', 'rbot profile directory. Defaults to: %s.' % options[:profile]) do |profile|
+ options[:profile] = profile
+ end
+
+ opt.on('-r', '--registry [REGISTRY]', 'registry-path to read/write, Optional, defaults to: <PROFILE>/registry_<TYPE>.') do |profile|
+ options[:registry] = profile