Class: FsSnapshoter
- Inherits:
-
Object
- Object
- FsSnapshoter
- Defined in:
- lib/fs-snapshoter.rb
Instance Attribute Summary collapse
-
#data_dir ⇒ Object
readonly
Returns the value of attribute data_dir.
-
#snapshots_dir ⇒ Object
readonly
Returns the value of attribute snapshots_dir.
Instance Method Summary collapse
-
#delete(name) ⇒ Object
Deletes a snapshot.
-
#initialize(data_dir, snapshots_dir) ⇒ FsSnapshoter
constructor
A new instance of FsSnapshoter.
-
#list ⇒ Object
Returns array of existing snapshots.
-
#restore(name) ⇒ Object
Restores a snapshot.
-
#take(name) ⇒ Object
Takes a snapshot.
Constructor Details
#initialize(data_dir, snapshots_dir) ⇒ FsSnapshoter
Returns a new instance of FsSnapshoter.
7 8 9 10 |
# File 'lib/fs-snapshoter.rb', line 7 def initialize(data_dir, snapshots_dir) @data_dir = Pathname.new(data_dir)..realpath @snapshots_dir = Pathname.new(snapshots_dir)..realpath end |
Instance Attribute Details
#data_dir ⇒ Object (readonly)
Returns the value of attribute data_dir.
5 6 7 |
# File 'lib/fs-snapshoter.rb', line 5 def data_dir @data_dir end |
#snapshots_dir ⇒ Object (readonly)
Returns the value of attribute snapshots_dir.
5 6 7 |
# File 'lib/fs-snapshoter.rb', line 5 def snapshots_dir @snapshots_dir end |
Instance Method Details
#delete(name) ⇒ Object
Deletes a snapshot.
38 39 40 41 |
# File 'lib/fs-snapshoter.rb', line 38 def delete(name) FileUtils.rm_r snapshot_dir(name) return true end |
#list ⇒ Object
Returns array of existing snapshots.
18 19 20 |
# File 'lib/fs-snapshoter.rb', line 18 def list @snapshots_dir.children(false).collect { |entry| entry.to_str } end |
#restore(name) ⇒ Object
Restores a snapshot.
31 32 33 34 35 |
# File 'lib/fs-snapshoter.rb', line 31 def restore(name) FileUtils.rm_rf @data_dir FileUtils.cp_r snapshot_dir(name).to_str + '/.', @data_dir return true end |
#take(name) ⇒ Object
Takes a snapshot.
23 24 25 26 27 28 |
# File 'lib/fs-snapshoter.rb', line 23 def take(name) dir = snapshot_dir(name) dir.mkdir FileUtils.cp_r @data_dir.to_str + '/.', dir return true end |