Module: FackUp

Defined in:
lib/fackup/image.rb,
lib/fackup.rb,
lib/fackup/db.rb,
lib/fackup/cli.rb

Overview

– Copyleft shura. [ [email protected] ]

This file is part of fackup.

fackup is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

fackup is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with fackup. If not, see <www.gnu.org/licenses/>. ++

Defined Under Namespace

Modules: DB Classes: CLI, Image

Constant Summary collapse

VERSION =
'0.0.1.2'

Class Method Summary collapse

Class Method Details

.backup(file) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fackup.rb', line 74

def self.backup (file)
  FackUp::Image.new(file, 'w', true) {|img|
    DB.each {|file|
      unless File.readable?(file)
        next
      end

      img << file
    }
  }
end

.restore(image) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fackup.rb', line 27

def self.restore (image)
  FackUp::Image.new(image, 'r', true) {|img|
    img.each {|file|
      FileUtils.mkdir_p(File.dirname(file.name))

      if File.exists?(file.name)
        stat = File.stat(file.name)

        next if file.time == stat.mtime and file.size == File.size(file.name) and
          file.uid == stat.uid and file.gid == stat.gid and file.mode == stat.mod
      end

      begin
        File.open(file.name, 'wb') {|f|
          f.write(file.content)
        }
      rescue Errno::EACCES
        next
      end

      File.chown(file.uid, file.gid, file.name)
      File.chmod(file.mode, file.name)
      File.utime(file.time, file.time, file.name)
    }
  }
end

.restore_f(image) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fackup.rb', line 54

def self.restore_f (image)
  FackUp::Image.new(image, 'r', true) {|img|
    img.each {|file|
      FileUtils.mkdir_p(File.dirname(file.name))

      begin
        File.open(file.name, 'wb') {|f|
          f.write(file.content)
        }
      rescue Errno::EACCES
        next
      end

      File.chown(file.uid, file.gid, file.name)
      File.chmod(file.mode, file.name)
      File.utime(file.time, file.time, file.name)
    }
  }
end