Class: VpsAdminOS::Converter::Cli::Vz6::Export

Inherits:
Base
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
Defined in:
lib/vpsadminos-converter/cli/vz6/export.rb

Instance Method Summary collapse

Methods inherited from Base

#convert_ct, #exporter_class, #print_convert_status

Methods inherited from Command

#initialize, run

Constructor Details

This class inherits a constructor from VpsAdminOS::Converter::Cli::Command

Instance Method Details

#exportObject



10
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
43
44
45
# File 'lib/vpsadminos-converter/cli/vz6/export.rb', line 10

def export
  require_args!('ctid', 'file')

  vz_ct, target_ct = convert_ct(args[0])

  File.open(args[1], 'w') do |f|
    exporter = exporter_class.new(
      target_ct,
      f,
      compression: opts[:compression].to_sym,
      compressed_send: opts['zfs-compressed-send']
    )

    puts 'Exporting metadata'
    exporter.('full')

    puts 'Exporting configs'
    exporter.dump_configs

    puts 'Exporting rootfs'

    if opts[:zfs]
      export_streams(vz_ct, exporter)

    elsif vz_ct.ploop?
      export_tar_ploop(vz_ct, exporter)

    else
      export_tar_simfs(vz_ct, exporter)
    end
  end

  puts 'Export done'
  puts
  print_convert_status(vz_ct)
end

#export_streams(vz_ct, exporter) ⇒ Object (protected)



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vpsadminos-converter/cli/vz6/export.rb', line 49

def export_streams(vz_ct, exporter)
  exporter.dump_rootfs do
    puts '> base stream'
    exporter.dump_base

    if vz_ct.running? && opts[:consistent]
      puts '> stopping container'
      syscmd("vzctl stop #{vz_ct.ctid}")

      puts '> incremental stream'
      exporter.dump_incremental

      puts '> restarting container'
      syscmd("vzctl start #{vz_ct.ctid}")
    end
  end
end

#export_tar_ploop(vz_ct, exporter) ⇒ Object (protected)



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/vpsadminos-converter/cli/vz6/export.rb', line 67

def export_tar_ploop(vz_ct, exporter)
  status = vz_ct.status

  if status[:running] && opts[:consistent]
    puts '> stopping container'
    syscmd("vzctl stop #{vz_ct.ctid}")
    syscmd("vzctl mount #{vz_ct.ctid}")

  elsif !status[:mounted]
    syscmd("vzctl mount #{vz_ct.ctid}")
  end

  puts '> packing rootfs'
  exporter.pack_rootfs
ensure
  if status[:running] && opts[:consistent]
    puts '> restarting container'
    syscmd("vzctl start #{vz_ct.ctid}")

  elsif !status[:mounted]
    syscmd("vzctl umount #{vz_ct.ctid}")
  end
end

#export_tar_simfs(vz_ct, exporter) ⇒ Object (protected)



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/vpsadminos-converter/cli/vz6/export.rb', line 91

def export_tar_simfs(vz_ct, exporter)
  running = vz_ct.running? && opts[:consistent]

  if running
    puts '> stopping container'
    syscmd("vzctl stop #{vz_ct.ctid}")
  end

  puts '> packing rootfs'
  exporter.pack_rootfs
ensure
  if running
    puts '> restarting container'
    syscmd("vzctl start #{vz_ct.ctid}")
  end
end