Class: OsCtld::Commands::Container::SendRootfs
- Includes:
- OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::Send, OsCtl::Lib::Utils::System
- Defined in:
- lib/osctld/commands/container/send_rootfs.rb
Instance Attribute Summary
Attributes inherited from Base
#client, #client_handler, #id, #opts
Instance Method Summary collapse
- #execute ⇒ Object
- #send_dataset(ct, ds, base_snap) ⇒ Object protected
- #send_snapshot(ct, ds, base_snap, snap, from_snap = nil) ⇒ Object protected
Methods inherited from Base
#base_execute, #call_cmd, #call_cmd!, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!
Constructor Details
This class inherits a constructor from OsCtld::Commands::Base
Instance Method Details
#execute ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/osctld/commands/container/send_rootfs.rb', line 11 def execute ct = DB::Containers.find(opts[:id], opts[:pool]) error!('container not found') unless ct manipulate(ct) do ct.exclusively do if !ct.send_log || !ct.send_log.can_send_continue?(:base) error!('invalid send sequence') end end snap = "osctl-send-base-#{Time.now.to_i}" zfs(:snapshot, '-r', "#{ct.dataset}@#{snap}") ct.exclusively do ct.send_log.snapshots << snap ct.save_config end send_dataset(ct, ct.dataset, snap) ct.dataset.descendants.each do |ds| send_dataset(ct, ds, snap) end ct.exclusively do ct.send_log.state = :base ct.save_config end end ok end |
#send_dataset(ct, ds, base_snap) ⇒ Object (protected)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/osctld/commands/container/send_rootfs.rb', line 46 def send_dataset(ct, ds, base_snap) progress("Syncing #{ds.relative_name}") if ct.send_log.opts.from_snapshot && ct.send_log.opts.preexisting_datasets send_snapshot(ct, ds, base_snap, base_snap, ct.send_log.opts.from_snapshot) elsif ct.send_log.opts.from_snapshot && !ct.send_log.opts.preexisting_datasets send_snapshot(ct, ds, base_snap, ct.send_log.opts.from_snapshot) send_snapshot(ct, ds, base_snap, base_snap, ct.send_log.opts.from_snapshot) elsif ct.send_log.opts.snapshots snaps = ds.snapshots send_snapshot(ct, ds, base_snap, snaps.first.snapshot) if snaps.count > 1 send_snapshot(ct, ds, base_snap, snaps.last.snapshot, snaps.first.snapshot) end else send_snapshot(ct, ds, base_snap, base_snap) end end |
#send_snapshot(ct, ds, base_snap, snap, from_snap = nil) ⇒ Object (protected)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/osctld/commands/container/send_rootfs.rb', line 68 def send_snapshot(ct, ds, base_snap, snap, from_snap = nil) stream = OsCtl::Lib::Zfs::Stream.new( ds, snap, from_snap, intermediary: ct.send_log.opts.snapshots ) stream.progress do |total, _transfered, changed| progress(type: :progress, data: { time: Time.now.to_i, size: stream.size, transfered: total, changed: }) end mbuf_opts = Daemon.get.config.send_receive.send_mbuffer. r, send = stream.spawn_with_mbuffer(**mbuf_opts) pid = Process.spawn( *send_ssh_cmd( ct.pool.send_receive_key_chain, ct.send_log.opts, [ 'receive', from_snap ? 'incremental' : 'base', ct.send_log.token, ds.relative_name ] + (base_snap == snap ? [base_snap] : []) ), in: r ) r.close send_status = stream.monitor(send) _, ssh_status = Process.wait2(pid) return unless send_status.exitstatus != 0 || ssh_status.exitstatus != 0 error!('sync failed') end |