Class: Qdumpfs::Option
- Inherits:
-
Object
- Object
- Qdumpfs::Option
- Defined in:
- lib/qdumpfs/option.rb
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#dirs ⇒ Object
readonly
Returns the value of attribute dirs.
-
#dst ⇒ Object
readonly
Returns the value of attribute dst.
-
#interval_proc ⇒ Object
readonly
Returns the value of attribute interval_proc.
-
#keep_day ⇒ Object
readonly
Returns the value of attribute keep_day.
-
#keep_month ⇒ Object
readonly
Returns the value of attribute keep_month.
-
#keep_week ⇒ Object
readonly
Returns the value of attribute keep_week.
-
#keep_year ⇒ Object
readonly
Returns the value of attribute keep_year.
-
#logdir ⇒ Object
readonly
Returns the value of attribute logdir.
-
#logfile ⇒ Object
readonly
Returns the value of attribute logfile.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#verifyfile ⇒ Object
readonly
Returns the value of attribute verifyfile.
Instance Method Summary collapse
- #detect_keep_dirs(backup_dirs) ⇒ Object
- #dry_run ⇒ Object
-
#initialize(opts, dirs) ⇒ Option
constructor
A new instance of Option.
- #limit_sec ⇒ Object
- #log(msg, console = true) ⇒ Object
- #open_listfile ⇒ Object
- #open_verifyfile ⇒ Object
- #report(type, filename) ⇒ Object
- #validate_directories(min_count) ⇒ Object
- #validate_directory(dir) ⇒ Object
Constructor Details
#initialize(opts, dirs) ⇒ Option
Returns a new instance of Option.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/qdumpfs/option.rb', line 104 def initialize(opts, dirs) @opts = opts @dirs = dirs @src = dirs[0] if dirs.size > 0 @dst = dirs[1] if dirs.size > 1 @cmd = @opts[:c] || 'backup' # @logger = NullLogger.new logfile = @opts[:logfile] || 'log.txt' #ログディレクトリの作成 @logdir = File.('.') Dir.mkdir(@logdir) unless FileTest.directory?(@logdir) @logpath = File.join(@logdir, logfile) @logger = SimpleLogger.new(@logpath) verifyfile = 'verify.txt' @verifypath = File.join(@logdir, verifyfile) @matcher = NullMatcher.new size = @opts[:es] globs = @opts[:eg] patterns = @opts[:ep] if size || globs || patterns @matcher = FileMatcher.new(:size => size, :globs => globs, :patterns => patterns) end # 同期用のオプションは日常使いのpdumpfs-cleanのオプションより期間短めに設定 @limit = @opts[:limit] @keep_year = 100 @keep_month = 12 @keep_week = 12 @keep_day = 30 keep = @opts[:keep] @keep_year = $1.to_i if keep =~ /(\d+)Y/ @keep_month = $1.to_i if keep =~ /(\d+)M/ @keep_week = $1.to_i if keep =~ /(\d+)W/ @keep_day = $1.to_i if keep =~ /(\d+)D/ @today = Date.today end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
144 145 146 |
# File 'lib/qdumpfs/option.rb', line 144 def cmd @cmd end |
#dirs ⇒ Object (readonly)
Returns the value of attribute dirs.
144 145 146 |
# File 'lib/qdumpfs/option.rb', line 144 def dirs @dirs end |
#dst ⇒ Object (readonly)
Returns the value of attribute dst.
144 145 146 |
# File 'lib/qdumpfs/option.rb', line 144 def dst @dst end |
#interval_proc ⇒ Object (readonly)
Returns the value of attribute interval_proc.
147 148 149 |
# File 'lib/qdumpfs/option.rb', line 147 def interval_proc @interval_proc end |
#keep_day ⇒ Object (readonly)
Returns the value of attribute keep_day.
145 146 147 |
# File 'lib/qdumpfs/option.rb', line 145 def keep_day @keep_day end |
#keep_month ⇒ Object (readonly)
Returns the value of attribute keep_month.
145 146 147 |
# File 'lib/qdumpfs/option.rb', line 145 def keep_month @keep_month end |
#keep_week ⇒ Object (readonly)
Returns the value of attribute keep_week.
145 146 147 |
# File 'lib/qdumpfs/option.rb', line 145 def keep_week @keep_week end |
#keep_year ⇒ Object (readonly)
Returns the value of attribute keep_year.
145 146 147 |
# File 'lib/qdumpfs/option.rb', line 145 def keep_year @keep_year end |
#logdir ⇒ Object (readonly)
Returns the value of attribute logdir.
146 147 148 |
# File 'lib/qdumpfs/option.rb', line 146 def logdir @logdir end |
#logfile ⇒ Object (readonly)
Returns the value of attribute logfile.
146 147 148 |
# File 'lib/qdumpfs/option.rb', line 146 def logfile @logfile end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
147 148 149 |
# File 'lib/qdumpfs/option.rb', line 147 def logger @logger end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
147 148 149 |
# File 'lib/qdumpfs/option.rb', line 147 def matcher @matcher end |
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
147 148 149 |
# File 'lib/qdumpfs/option.rb', line 147 def reporter @reporter end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
144 145 146 |
# File 'lib/qdumpfs/option.rb', line 144 def src @src end |
#verifyfile ⇒ Object (readonly)
Returns the value of attribute verifyfile.
146 147 148 |
# File 'lib/qdumpfs/option.rb', line 146 def verifyfile @verifyfile end |
Instance Method Details
#detect_keep_dirs(backup_dirs) ⇒ Object
207 208 209 210 211 212 |
# File 'lib/qdumpfs/option.rb', line 207 def detect_keep_dirs(backup_dirs) detect_year_keep_dirs(backup_dirs) detect_month_keep_dirs(backup_dirs) detect_week_keep_dirs(backup_dirs) detect_day_keep_dirs(backup_dirs) end |
#dry_run ⇒ Object
177 178 179 |
# File 'lib/qdumpfs/option.rb', line 177 def dry_run @opts[:n] end |
#limit_sec ⇒ Object
181 182 183 |
# File 'lib/qdumpfs/option.rb', line 181 def limit_sec @limit.to_i * 3600 end |
#log(msg, console = true) ⇒ Object
171 172 173 174 175 |
# File 'lib/qdumpfs/option.rb', line 171 def log(msg, console = true) return if (msg.nil? || msg == '') puts msg if console @logger.print(msg) end |
#open_listfile ⇒ Object
221 222 223 224 225 226 227 |
# File 'lib/qdumpfs/option.rb', line 221 def open_listfile filename = File.join(@logdir, "list_" + @src.gsub(/[:\/]/, '_') + '.txt') if FileTest.file?(filename) File.unlink(filename) end File.open(filename, 'a') end |
#open_verifyfile ⇒ Object
214 215 216 217 218 219 |
# File 'lib/qdumpfs/option.rb', line 214 def open_verifyfile if FileTest.file?(@verifypath) File.unlink(@verifypath) end File.open(@verifypath, 'a') end |
#report(type, filename) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/qdumpfs/option.rb', line 149 def report(type, filename) if @opts[:v] stat = File.stat(filename) size = stat.size format_size = convert_bytes(size) msg = format_report_with_size(type, filename, size, format_size) elsif @opts[:r] if type =~ /^new_file/ stat = File.stat(filename) size = stat.size format_size = convert_bytes(size) msg = format_report_with_size(type, filename, size, format_size) end else # 何も指定されていない場合 if type == 'new_file' msg = format_report(type, filename) end end log(msg) end |
#validate_directories(min_count) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/qdumpfs/option.rb', line 191 def validate_directories(min_count) @dirs.each do |dir| validate_directory(dir) end if @dirs.size == 2 && windows? # ディレクトリが2つだけ指定されている場合、コピー先はntfsである必要がある unless ntfs?(dst) fstype = get_filesystem_type(dst) raise sprintf("only NTFS is supported but %s is %s.", dst, fstype) end end if @dirs.size < min_count raise "#{min_count} directories required." end end |
#validate_directory(dir) ⇒ Object
185 186 187 188 189 |
# File 'lib/qdumpfs/option.rb', line 185 def validate_directory(dir) if dir.nil? || !File.directory?(dir) raise ArgumentError, "No such directory: #{dir}" end end |