Class: VpsAdminOS::Converter::Vz6::Migrator::Zfs
- Defined in:
- lib/vpsadminos-converter/vz6/migrator/zfs.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #cancel(cmd_opts) ⇒ Object
- #cleanup(cmd_opts) ⇒ Object
- #send_dataset(ct, ds, base_snap) ⇒ Object protected
- #send_dataset_incr(ct, ds, incr_snap, from_snap) ⇒ Object protected
- #send_snapshot(ct, ds, base_snap, snap, from_snap = nil) ⇒ Object protected
- #sync(&block) ⇒ Object
- #transfer(&block) ⇒ Object
Methods inherited from Base
#cancel_remote, #export_skel, #initialize, #progress, #stage, #transfer_container
Constructor Details
This class inherits a constructor from VpsAdminOS::Converter::Vz6::Migrator::Base
Instance Method Details
#cancel(cmd_opts) ⇒ Object
65 66 67 68 |
# File 'lib/vpsadminos-converter/vz6/migrator/zfs.rb', line 65 def cancel(cmd_opts) cancel_remote(cmd_opts[:force]) state.destroy end |
#cleanup(cmd_opts) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vpsadminos-converter/vz6/migrator/zfs.rb', line 50 def cleanup(cmd_opts) target_ct.datasets.each do |ds| state.snapshots.each do |snap| zfs(:destroy, nil, "#{ds}@#{snap}") end end if cmd_opts[:delete] syscmd("vzctl destroy #{vz_ct.ctid}") zfs(:destroy, '-r', target_ct.dataset) end state.destroy end |
#send_dataset(ct, ds, base_snap) ⇒ Object (protected)
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/vpsadminos-converter/vz6/migrator/zfs.rb', line 72 def send_dataset(ct, ds, base_snap) progress(:step, "Syncing #{ds.relative_name}") snaps = ds.snapshots send_snapshot(ct, ds, base_snap, snaps.first.snapshot) return unless snaps.count > 1 send_snapshot( ct, ds, base_snap, snaps.last.snapshot, snaps.first.snapshot ) end |
#send_dataset_incr(ct, ds, incr_snap, from_snap) ⇒ Object (protected)
88 89 90 91 |
# File 'lib/vpsadminos-converter/vz6/migrator/zfs.rb', line 88 def send_dataset_incr(ct, ds, incr_snap, from_snap) progress(:step, "Syncing #{ds.relative_name}") send_snapshot(ct, ds, incr_snap, incr_snap, from_snap) end |
#send_snapshot(ct, ds, base_snap, snap, from_snap = nil) ⇒ Object (protected)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/vpsadminos-converter/vz6/migrator/zfs.rb', line 93 def send_snapshot(ct, ds, base_snap, snap, from_snap = nil) stream = OsCtl::Lib::Zfs::Stream.new( ds, snap, from_snap, compressed: opts[:zfs_compressed_send] ) stream.progress do |total, _transfered, _changed| progress(:transfer, [stream.size, total]) end r, send = stream.spawn pid = Process.spawn( *migrate_ssh_cmd( nil, opts, [ 'receive', from_snap ? 'incremental' : 'base', ct.id, ds.relative_name ] + (base_snap == snap ? [base_snap] : []) ), in: r ) r.close stream.monitor(send) _, status = Process.wait2(pid) raise 'sync failed' if status.exitstatus != 0 end |
#sync(&block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vpsadminos-converter/vz6/migrator/zfs.rb', line 5 def sync(&block) self.progress_handler = block if opts[:zfs_subdir] != 'private' raise 'only zfs-subdir=private is implemented' end snap = "converter-migrate-base-#{Time.now.to_i}" zfs(:snapshot, '-r', "#{state.target_ct.dataset}@#{snap}") state.set_step(:sync) state.snapshots << snap state.save state.target_ct.datasets.each do |ds| send_dataset(state.target_ct, ds, snap) end end |
#transfer(&block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vpsadminos-converter/vz6/migrator/zfs.rb', line 24 def transfer(&block) self.progress_handler = block if opts[:zfs_subdir] != 'private' raise 'only zfs-subdir=private is implemented' end # Stop the container running = vz_ct.running? syscmd("vzctl stop #{vz_ct.ctid}") # Final sync snap = "converter-migrate-incr-#{Time.now.to_i}" zfs(:snapshot, '-r', "#{target_ct.dataset}@#{snap}") state.snapshots << snap state.save state.target_ct.datasets.each do |ds| send_dataset_incr(target_ct, ds, snap, state.snapshots[-2]) end # Transfer to dst transfer_container(running) end |