Module: Bizside::Rsync

Defined in:
lib/bizside/rsync.rb

Class Method Summary collapse

Class Method Details

.cleanup_old_dirs(backup_dirs, generations) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/bizside/rsync.rb', line 4

def self.cleanup_old_dirs(backup_dirs, generations)
  if backup_dirs.size > generations
    puts '--------------------'
    while backup_dirs.size > generations
      old_backup_dir = backup_dirs.shift
      puts "古いバックアップを削除します。#{old_backup_dir}"
      FileUtils.rm_r(old_backup_dir, :force => true)
    end
    puts '--------------------'
  end
end

.get_backup_dirs(backup_base_dir) ⇒ Object

YYYYMMDDHHMMSS形式.failed や .running は除外する



33
34
35
36
37
# File 'lib/bizside/rsync.rb', line 33

def self.get_backup_dirs(backup_base_dir)
  ret = Dir::glob(File.join(backup_base_dir, '2*')).reject{|dir| File.basename(dir).index('.') }
  ret = ret.sort
  ret
end

.next_generation(backup_dir) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bizside/rsync.rb', line 16

def self.next_generation(backup_dir)
  running_dir = backup_dir + '.running'
  failure_dir = backup_dir + '.failed'

  begin
    FileUtils.ln_s(backup_dir, running_dir)
    yield
  rescue => e
    FileUtils.ln_s(backup_dir, failure_dir)
    raise e
  ensure
    FileUtils.rm_f(running_dir)
  end
end