とりあえずtapを覚えた
ファイルのhash取り込みも
snapshot.rb
#!/usr/bin/env ruby require 'date' 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 = get_conf(conf).tap{|h| h.each_pair{|src, dst| _src = src.sub(/$\//,"").split(/\s*\/\s*/) if _src.size == 0 h[src] = "#{dst}/rootfs_#{Time.now.strftime("%Y%m%d%H%M").to_s}" else h[src] = "#{dst}/#{_src[_src.size - 1]}_#{Time.now.strftime("%Y%m%d%H%M").to_s}" end } } 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