Class: FsSnapshoter

Inherits:
Object
  • Object
show all
Defined in:
lib/fs-snapshot/fs-snapshoter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_dir, snapshots_dir) ⇒ FsSnapshoter

Returns a new instance of FsSnapshoter.



7
8
9
10
# File 'lib/fs-snapshot/fs-snapshoter.rb', line 7

def initialize(data_dir, snapshots_dir)
	@data_dir = Pathname.new(data_dir).expand_path.realpath
	@snapshots_dir = Pathname.new(snapshots_dir).expand_path.realpath
end

Instance Attribute Details

#data_dirObject (readonly)

Returns the value of attribute data_dir.



5
6
7
# File 'lib/fs-snapshot/fs-snapshoter.rb', line 5

def data_dir
  @data_dir
end

#snapshots_dirObject (readonly)

Returns the value of attribute snapshots_dir.



5
6
7
# File 'lib/fs-snapshot/fs-snapshoter.rb', line 5

def snapshots_dir
  @snapshots_dir
end

Instance Method Details

#delete(name) ⇒ Object

Deletes a snapshot.



40
41
42
43
44
# File 'lib/fs-snapshot/fs-snapshoter.rb', line 40

def delete(name)
	raise "No such snapshot - '#{name}'!" unless list.include? name
	FileUtils.rm_r snapshot_dir(name)
	return true
end

#listObject

Returns array of existing snapshots.



18
19
20
# File 'lib/fs-snapshot/fs-snapshoter.rb', line 18

def list
	@snapshots_dir.children(false).collect { |entry| entry.to_s }
end

#restore(name) ⇒ Object

Restores a snapshot.



32
33
34
35
36
37
# File 'lib/fs-snapshot/fs-snapshoter.rb', line 32

def restore(name)
	raise "No such snapshot - '#{name}'!" unless list.include? name
	FileUtils.rm_rf @data_dir
	FileUtils.cp_r snapshot_dir(name).to_s + '/.', @data_dir
	return true
end

#take(name) ⇒ Object

Takes a snapshot.



23
24
25
26
27
28
29
# File 'lib/fs-snapshot/fs-snapshoter.rb', line 23

def take(name)
	raise "Snapshot already exists - '#{name}'!" if list.include? name
	dir = snapshot_dir(name)
	dir.mkdir
	FileUtils.cp_r @data_dir.to_s + '/.', dir
	return true
end