メモを残す
#!/usr/bin/env ruby require 'date' def parse_dir(conf) snap = Hash::new # hoge.tap{|h| hoge.each_pair{|src, dst| h[src] = "a"} } conf.each_pair {|src, dst| _src = src.sub(/$\//,"").split(/\s*\/\s*/) if _src.size == 0 snap[src] = "#{dst}/rootfs_#{Time.now.strftime("%Y%m%d").to_s}" else snap[src] = "#{dst}/#{_src[_src.size - 1].strip}_#{Time.now.strftime("%Y%m%d").to_s}" end } return snap end def get_conf(conf_file) conf = Hash[*open(conf_file).read.split(/\n/).map{|f| f.split}.flatten] return conf end class Snapshot def initialize(conf = "/etc/snap.conf") @snap = parse_dir(get_conf(conf)) end def do_snap @snap.each_pair {|src, dst| system("btrfs","sub","snap",src,dst) } end end if ARGV[0] == nil snap = Snapshot.new else if File::ftype(ARGV[0]) == "file" snap = Snapshot.new(ARGV[0]) else p "no such file" end end if snap != nil snap.do_snap end
No comments:
Post a Comment