Class: Qdumpfs::Command
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opt) ⇒ Command
constructor
A new instance of Command.
- #run ⇒ Object
Methods included from QdumpfsUtils
#chown_if_root, #convert_bytes, #copy, #copy_file, #create_latest_symlink, #datedir, #detect_type, #fmt, #fputs, #link, #make_relative_path, #past_date?, #restore_dir_attributes, #same_directory?, #same_file?, #sub_directory?, #time_diff, #to_time, #to_unix_path, #to_win_path
Constructor Details
#initialize(opt) ⇒ Command
Returns a new instance of Command.
84 85 86 |
# File 'lib/qdumpfs.rb', line 84 def initialize(opt) @opt = opt end |
Class Method Details
.run(argv) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/qdumpfs.rb', line 17 def self.run(argv) args = argv.clone STDOUT.sync = true opts = {} opt = OptionParser.new(argv) opt.version = VERSION opt. = "Usage: #{opt.program_name} [options] <source> <dest>" opt.separator('Options') opt.on_head('-h', '--help', 'show this message') do |v| puts opt.help exit end opt.on('-v', '--verbose', 'verbose message') {|v| opts[:v] = v} opt.on('-r', '--report', 'report message') {|v| opts[:r] = v} opt.on('-n', '--dry-run', "don't actually run any commands") {|v| opts[:n] = v} opt.on('-e PATTERN', '--exclude=PATTERN', 'exclude files/directories matching PATTERN') {|v| opts[:ep] = [] if opts[:ep].nil? opts[:ep] << Regexp.new(v) } opt.on('-s SIZE', '--exclude-by-size=SIZE', 'exclude files larger than SIZE') {|v| opts[:es] = v } opt.on('-w GLOB', '--exclude-by-glob=GLOB', 'exclude files matching GLOB') {|v| opts[:eg] = v } commands = ['backup', 'sync', 'list', 'expire', 'verify', 'delete'] opt.on('-c COMMAND', '--command=COMMAND', commands, commands.join('|')) {|v| opts[:c] = v} opt.on('-l HOURS', '--limit=HOURS', 'limit hours') {|v| opts[:limit] = v} opt.on('-k KEEPARG', '--keep=KEEPARG', 'ex: --keep 100Y12M12W30D (100years, 12months, 12weeks, 30days, default)') {|v| opts[:keep] = v} opt.on('--logdir=LOGDIR', 'logdir') {|v| opts[:logdir] = v} opt.on('--logname=LOGNAME', 'logname') {|v| opts[:logname] = v} opt.on('--logpath=LOGPATH', 'logpath') {|v| opts[:logpath] = v} opt.on('--delete-from=YYYYMMDD', 'delete backup from YYYY/MM/DD') {|v| opts[:delete_from] = Date.parse(v) } opt.on('--delete-to=YYYYMMDD', 'delete backup to YYYY/MM/DD') {|v| opts[:delete_to] = Date.parse(v) } opt.on('--delete-dir=DIRS', 'relative path from the snapshot root of the backup. ex: --delete-dir=foo,home/bar') {|v| opts[:delete_dirs] = v.split(/,/) } opt.on('--backup-at=YYYYMMDD', 'backup at YYYY/MM/DD') {|v| opts[:backup_at] = Date.parse(v) } opt.on('-d', '--debug', 'debug mode') {|v| opts[:d] = v } opt.parse!(argv) option = Option.new(opts, argv) if opts[:v] puts "<<<<< qdumpfs options >>>>> " args = args.join(' ') puts "args: #{args}" puts "logdir: #{option.logdir}" puts "logpath: #{option.logpath}" puts "verifypath: #{option.verifypath}" puts end begin command = Command.new(option) command.run rescue => e puts e. + "\n" if option.debug p e.backtrace end puts opt.help exit ensure option.close end end |
Instance Method Details
#run ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/qdumpfs.rb', line 88 def run if @opt.cmd == 'backup' backup elsif @opt.cmd == 'sync' sync elsif @opt.cmd == 'list' list elsif @opt.cmd == 'expire' delete('expire') elsif @opt.cmd == 'verify' verify elsif @opt.cmd == 'delete' delete('delete') else raise RuntimeError, "unknown command: #{@opt.cmd}" end end |