lib/qdumpfs.rb in qdumpfs-1.0.1 vs lib/qdumpfs.rb in qdumpfs-1.1.0
- old
+ new
@@ -98,23 +98,33 @@
private
def log_result(src, today, elapsed)
time = Time.now.strftime("%Y-%m-%dT%H:%M:%S")
bytes = convert_bytes(@written_bytes)
- msg = sprintf("%s: %s -> %s (in %.2f sec, %s written)\n",
- time, src, today, elapsed, bytes)
+ msg = sprintf("%s: %s -> %s (in %.2f sec, %s written)\n", time, src, today, elapsed, bytes)
log(msg)
+ log("error files:\n")
+ i = 1
+ @error_files.each do |filename, reason|
+ msg = "#{i}. #{filename}\t#{reason}\n"
+ log(msg)
+ i += 1
+ end
end
def log(msg, console = true)
@opt.log(msg, console)
end
def report(type, file_name)
@opt.report(type, file_name)
end
+ def report_error(file_name, reason)
+ @opt.report_error(file_name, reason)
+ end
+
def update_file(src, latest, today)
type = detect_type(src, latest)
report(type, src)
return if @opt.dry_run
case type
@@ -178,11 +188,12 @@
begin
# ファイルのアップデート
update_file(s, l, t)
dirs[t] = File.stat(s) if File.ftype(s) == "directory"
rescue => e
- log("#{src}: #{e.message}")
+ report_error(s, e.message)
+ @error_files << [s, e.message]
next
end
end
return if @opt.dry_run
restore_dir_attributes(dirs)
@@ -213,11 +224,12 @@
raise "#{type}: shouldn't be reached here"
end
chown_if_root(type, s, t)
dirs[t] = File.stat(s) if File.ftype(s) == "directory"
rescue => e
- log("#{src}: #{e.message}")
+ report_error(s, e.message)
+ @error_files << [s, e.message]
next
end
end
restore_dir_attributes(dirs) unless @opt.dry_run
end
@@ -293,10 +305,11 @@
@opt.validate_directories(2)
log("##### backup start #####")
@written_bytes = 0
+ @error_files = []
start_time = Time.now
if @opt.backup_at
start_time = to_time(@opt.backup_at)
end
src = @opt.src
@@ -349,10 +362,11 @@
##### バックアップフォルダの同期ルーチン(バックアップディスクを他のディスクと同じ状態にする)
@opt.validate_directories(2)
start_time = Time.now
@written_bytes = 0
+ @error_files = []
src = @opt.src
dst = @opt.dst
# 制限時間まで繰り返す(指定がない場合1回で終了)
limit_time = start_time + (@opt.limit_sec)
@@ -395,9 +409,13 @@
end
end
end_time = Time.now
diff = time_diff(start_time, end_time)
+
+ elapsed = Time.now - start_time
+ log_result(src, dst, elapsed)
+
log("##### sync end #{fmt(end_time)} diff=#{diff} last_sync_complete=#{last_sync_complete} #####")
end
def verify
file = @opt.open_verifyfile