-begin; require 'rubygems'; rescue Exception; puts "[#{$!}]"; end
-begin; require 'dbm'; rescue Exception; puts "[#{$!}]"; end
-begin; require 'bdb'; rescue Exception; puts "[#{$!}]"; end
-begin; require 'tokyocabinet'; rescue Exception; puts "[#{$!}]"; end
-
-puts 'RBot registry backup/import script.'
-puts 'Ruby: %s | DBM: %s | BDB: %s | TC: %s' % [RUBY_VERSION,
- (DBM::VERSION rescue '-'),
- (BDB::VERSION rescue '-'),
- (TokyoCabinet::VERSION rescue '-')]
-
-if ARGV.length > 3 or ARGV.length < 2
- puts """
- Usage rbotdb [backup|restore] <BACKUP/RESTORE-FILE> [<PROFILE>]
-
- Examples:
- rbotdb backup ~/rbot_db_backup.yaml
- rbotdb backup ~/rbot_db_backup.yaml.gz ~/.rbot_two
- rbotdb restore ~/rbot_db_backup.yaml
- """
- exit
+begin; require 'rubygems'; rescue Exception; end
+
+# load registry formats:
+begin; require 'bdb'; rescue Exception; end
+begin; require 'tokyocabinet'; rescue Exception; end
+begin; require 'dbm'; rescue Exception; end
+begin; require 'daybreak'; rescue Exception; end
+begin; require 'sqlite3'; rescue Exception; end
+
+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
+ end
+
+ opt.on('-f', '--file [DBFILE]', 'cross-platform file to backup to/restore from. Defaults to: %s.' % options[:dbfile]) do |dbfile|
+ options[:dbfile] = dbfile
+ end
+
+ opt.separator ''