avm-tools 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/avm.rb +1 -0
- data/lib/avm/data.rb +9 -0
- data/lib/avm/data/instance.rb +11 -0
- data/lib/avm/data/instance/package.rb +18 -0
- data/lib/avm/data/instance/unit.rb +17 -0
- data/lib/avm/data/package.rb +42 -0
- data/lib/avm/data/package/dump.rb +116 -0
- data/lib/avm/data/package/load.rb +48 -0
- data/lib/avm/data/unit.rb +83 -0
- data/lib/avm/stereotypes/eac_wordpress_base0/instance.rb +20 -0
- data/lib/avm/stereotypes/eac_wordpress_base0/uploads_data_unit.rb +36 -0
- data/lib/avm/stereotypes/postgresql/instance.rb +6 -0
- data/lib/avm/stereotypes/postgresql/instance/data_unit.rb +41 -0
- data/lib/avm/tools/runner/eac_wordpress_base0/data/dump.rb +14 -55
- data/lib/avm/tools/runner/eac_wordpress_base0/data/load.rb +5 -28
- data/lib/avm/tools/version.rb +1 -1
- metadata +28 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e358cd10846dd42a33702ee9bcc47ac075d2c2df7e4019aff7876055d3e98d3
|
4
|
+
data.tar.gz: 198439929cad2eeeea336efff95b90c1a19fd83d187ba49e33f7ba9d77f49b84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e158e9238bb5283e8797dc7be877f1c76a76c64f2cfe43ac360a28d378555abcff90ce55b07f0bb145f17e9c7af43a3456c66e12ae1a22d8c2bf6fa92ab8c01a
|
7
|
+
data.tar.gz: f86650bedb0fff3104e595dfb69ceb42bf60209a66af36e8ff96e500a7ee8720f8151071d6d6d6ff36bd4272f755a7818ad90f401288f441223907f889304311
|
data/lib/avm.rb
CHANGED
data/lib/avm/data.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/data/package'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Data
|
7
|
+
module Instance
|
8
|
+
class Package < ::Avm::Data::Package
|
9
|
+
attr_reader :instance
|
10
|
+
|
11
|
+
def initialize(instance, options = {})
|
12
|
+
@instance = instance
|
13
|
+
super options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/data/unit'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Data
|
7
|
+
module Instance
|
8
|
+
class Unit < ::Avm::Data::Unit
|
9
|
+
attr_reader :instance
|
10
|
+
|
11
|
+
def initialize(instance)
|
12
|
+
@instance = instance
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/data/package/dump'
|
4
|
+
require 'avm/data/package/load'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Data
|
8
|
+
class Package
|
9
|
+
attr_reader :units
|
10
|
+
|
11
|
+
def initialize(options)
|
12
|
+
@units = {}
|
13
|
+
options = options.to_options_consumer
|
14
|
+
units = options.consume(:units)
|
15
|
+
options.validate
|
16
|
+
units.if_present do |v|
|
17
|
+
v.each { |identifier, unit| add_unit(identifier, unit) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_unit(identifier, unit)
|
22
|
+
@units[identifier.to_sym] = unit
|
23
|
+
end
|
24
|
+
|
25
|
+
def dump(data_path, options = {})
|
26
|
+
::Avm::Data::Package::Dump.new(self, data_path, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def load(data_path)
|
30
|
+
::Avm::Data::Package::Load.new(self, data_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def dump_units_to_directory(directory)
|
34
|
+
@units.each { |identifier, unit| unit.dump_to_directory(directory, identifier) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def load_units_from_directory(directory)
|
38
|
+
@units.each { |identifier, unit| unit.load_from_directory(directory, identifier) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'minitar'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Data
|
8
|
+
class Package
|
9
|
+
class Dump
|
10
|
+
enable_console_speaker
|
11
|
+
enable_listable
|
12
|
+
|
13
|
+
DEFAULT_EXPIRE_TIME = 1.days
|
14
|
+
|
15
|
+
attr_reader :package, :data_file_path, :existing
|
16
|
+
|
17
|
+
lists.add_string :existing, :denied, :overwrite, :rotate, :rotate_expired
|
18
|
+
|
19
|
+
def initialize(package, data_file_path, options = {})
|
20
|
+
@package = package
|
21
|
+
@data_file_path = data_file_path
|
22
|
+
options = options.to_options_consumer
|
23
|
+
@existing, @expire_time = options.consume(:existing, :expire_time)
|
24
|
+
options.validate
|
25
|
+
self.class.lists.existing.value_validate!(@existing)
|
26
|
+
end
|
27
|
+
|
28
|
+
def runnable?
|
29
|
+
cannot_run_reason.blank?
|
30
|
+
end
|
31
|
+
|
32
|
+
def cannot_run_reason
|
33
|
+
return nil if !data_file_exist? ||
|
34
|
+
[EXISTING_OVERWRITE, EXISTING_ROTATE].include?(existing)
|
35
|
+
|
36
|
+
if existing == EXISTING_DENIED
|
37
|
+
'Data exist and overwriting is denied'
|
38
|
+
elsif existing == EXISTING_ROTATE_EXPIRED && !data_file_expired?
|
39
|
+
'Data exist and yet is not expired'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def run
|
44
|
+
raise "Cannot run: #{cannot_run_reason}" unless runnable?
|
45
|
+
|
46
|
+
build_dir = dump_units_to_build_directory
|
47
|
+
package_file = create_package_file(build_dir)
|
48
|
+
rotate
|
49
|
+
move_download_to_final_dest(package_file)
|
50
|
+
end
|
51
|
+
|
52
|
+
def data_file_exist?
|
53
|
+
::File.exist?(data_file_path)
|
54
|
+
end
|
55
|
+
|
56
|
+
def data_file_time
|
57
|
+
data_file_exist? ? ::Time.now - ::File.mtime(data_file_path) : nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def data_file_expired?
|
61
|
+
data_file_time.if_present(false) { |v| v >= expire_time }
|
62
|
+
end
|
63
|
+
|
64
|
+
def expire_time
|
65
|
+
@expire_time || DEFAULT_EXPIRE_TIME
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def download
|
71
|
+
infom 'Downloading dump...'
|
72
|
+
download_path = find_download_path
|
73
|
+
dump_command.system!(output_file: download_path)
|
74
|
+
fatal_error "File \"#{download_path}\" not saved" unless ::File.exist?(download_path)
|
75
|
+
fatal_error "File \"#{download_path}\" is empty" if ::File.zero?(download_path)
|
76
|
+
download_path
|
77
|
+
end
|
78
|
+
|
79
|
+
def move_download_to_final_dest(download_path)
|
80
|
+
::FileUtils.mv(download_path, data_file_path)
|
81
|
+
end
|
82
|
+
|
83
|
+
def rotate
|
84
|
+
return unless data_file_exist?
|
85
|
+
return unless existing == EXISTING_ROTATE
|
86
|
+
|
87
|
+
infom "Rotating \"#{data_file_path}\"..."
|
88
|
+
::Avm::Files::Rotate.new(data_file_path).run
|
89
|
+
end
|
90
|
+
|
91
|
+
def new_build_path
|
92
|
+
f = ::Tempfile.new(self.class.name.parameterize + '-download')
|
93
|
+
path = f.path
|
94
|
+
f.close
|
95
|
+
f.unlink
|
96
|
+
path
|
97
|
+
end
|
98
|
+
|
99
|
+
def dump_units_to_build_directory
|
100
|
+
dir = ::Dir.mktmpdir
|
101
|
+
package.dump_units_to_directory(dir)
|
102
|
+
dir
|
103
|
+
end
|
104
|
+
|
105
|
+
def create_package_file(build_dir)
|
106
|
+
package_path = new_build_path
|
107
|
+
infom "Creating package \"#{package_path}\" from \"#{build_dir}\"..."
|
108
|
+
Dir.chdir(build_dir) do
|
109
|
+
::Minitar.pack('.', File.open(::File.expand_path(package_path), 'wb'))
|
110
|
+
end
|
111
|
+
package_path
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'minitar'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Data
|
8
|
+
class Package
|
9
|
+
class Load
|
10
|
+
enable_console_speaker
|
11
|
+
|
12
|
+
attr_reader :package, :data_file_path
|
13
|
+
|
14
|
+
def initialize(package, data_file_path)
|
15
|
+
@package = package
|
16
|
+
@data_file_path = data_file_path
|
17
|
+
end
|
18
|
+
|
19
|
+
def runnable?
|
20
|
+
cannot_run_reason.blank?
|
21
|
+
end
|
22
|
+
|
23
|
+
def cannot_run_reason
|
24
|
+
return nil if data_file_exist?
|
25
|
+
|
26
|
+
"Data file \"#{data_file_path}\" does not exist"
|
27
|
+
end
|
28
|
+
|
29
|
+
def run
|
30
|
+
raise "Cannot run: #{cannot_run_reason}" unless runnable?
|
31
|
+
|
32
|
+
build_dir = extract_packages_to_build_directory
|
33
|
+
package.load_units_from_directory(build_dir)
|
34
|
+
end
|
35
|
+
|
36
|
+
def data_file_exist?
|
37
|
+
::File.exist?(data_file_path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def extract_packages_to_build_directory
|
41
|
+
dir = ::Dir.mktmpdir
|
42
|
+
::Minitar.unpack(data_file_path, dir)
|
43
|
+
dir
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'active_support/callbacks'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Data
|
8
|
+
class Unit
|
9
|
+
include ::ActiveSupport::Callbacks
|
10
|
+
|
11
|
+
define_callbacks :dump, :load
|
12
|
+
enable_console_speaker
|
13
|
+
|
14
|
+
%w[dump load].each do |action|
|
15
|
+
class_eval <<~CODE, __FILE__, __LINE__ + 1
|
16
|
+
# Should be overrided.
|
17
|
+
# @return [EacRubyUtils::Envs::Command]
|
18
|
+
def #{action}_command
|
19
|
+
fail "Abstract method. Override in #{singleton_class}."
|
20
|
+
end
|
21
|
+
CODE
|
22
|
+
|
23
|
+
# Callbacks
|
24
|
+
%w[before after].each do |callback|
|
25
|
+
method = "#{callback}_#{action}"
|
26
|
+
class_eval <<~CODE, __FILE__, __LINE__ + 1
|
27
|
+
def self.#{method}(callback_method = nil, &block)
|
28
|
+
if callback_method
|
29
|
+
set_callback :#{action}, :#{callback}, callback_method
|
30
|
+
else
|
31
|
+
set_callback :#{action}, :#{callback}, &block
|
32
|
+
end
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def #{method}(callback_method = nil, &block)
|
37
|
+
singleton_class.#{method}(callback_method, &block)
|
38
|
+
self
|
39
|
+
end
|
40
|
+
CODE
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def extension
|
45
|
+
singleton_class.const_get('EXTENSION')
|
46
|
+
rescue NameError
|
47
|
+
''
|
48
|
+
end
|
49
|
+
|
50
|
+
def name
|
51
|
+
self.class
|
52
|
+
end
|
53
|
+
|
54
|
+
def load_from_directory(directory, identifier)
|
55
|
+
load(unit_on_directory_path(directory, identifier))
|
56
|
+
end
|
57
|
+
|
58
|
+
def dump_to_directory(directory, identifier)
|
59
|
+
dump(unit_on_directory_path(directory, identifier))
|
60
|
+
end
|
61
|
+
|
62
|
+
def dump(data_path)
|
63
|
+
run_callbacks :dump do
|
64
|
+
infom "Dumping unit \"#{name}\" to \"#{data_path}\"..."
|
65
|
+
dump_command.execute!(output_file: data_path)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def load(data_path)
|
70
|
+
run_callbacks :load do
|
71
|
+
infom "Loading unit \"#{name}\" from \"#{data_path}\"..."
|
72
|
+
load_command.execute!(input_file: data_path)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def unit_on_directory_path(directory, identifier)
|
79
|
+
::File.join(directory, "#{identifier}#{extension}")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'avm/instances/base'
|
4
4
|
require 'avm/stereotypes/postgresql/instance_with'
|
5
|
+
require 'avm/data/instance/package'
|
6
|
+
require 'avm/stereotypes/eac_wordpress_base0/uploads_data_unit'
|
5
7
|
|
6
8
|
module Avm
|
7
9
|
module Stereotypes
|
@@ -17,6 +19,24 @@ module Avm
|
|
17
19
|
parent = ::OpenStruct.new(instance: self)
|
18
20
|
subcommand_class.new(argv: argv, parent: parent).run
|
19
21
|
end
|
22
|
+
|
23
|
+
def data_package
|
24
|
+
@data_package ||= ::Avm::Data::Instance::Package.new(
|
25
|
+
self, units: { database: database_unit, uploads: UploadsDataUnit.new(self) }
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def database_unit
|
30
|
+
self_instance = self
|
31
|
+
pg.data_unit.after_load do
|
32
|
+
info 'Fixing web addresses...'
|
33
|
+
run_sql(<<~SQL)
|
34
|
+
update wp_options
|
35
|
+
set option_value = '#{self_instance.read_entry('url')}'
|
36
|
+
where option_name in ('siteurl', 'home')
|
37
|
+
SQL
|
38
|
+
end
|
39
|
+
end
|
20
40
|
end
|
21
41
|
end
|
22
42
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'minitar'
|
4
|
+
require 'zlib'
|
5
|
+
require 'avm/data/instance/unit'
|
6
|
+
|
7
|
+
module Avm
|
8
|
+
module Stereotypes
|
9
|
+
module EacWordpressBase0
|
10
|
+
class Instance < ::Avm::Instances::Base
|
11
|
+
class UploadsDataUnit < ::Avm::Data::Instance::Unit
|
12
|
+
EXTENSION = '.tar.gz'
|
13
|
+
|
14
|
+
before_load :clear_uploads
|
15
|
+
|
16
|
+
def uploads_path
|
17
|
+
::File.join(instance.read_entry(:fs_path), 'wp-content', 'uploads')
|
18
|
+
end
|
19
|
+
|
20
|
+
def dump_command
|
21
|
+
instance.host_env.command('tar', '-czf', '-', '-C', uploads_path, '.')
|
22
|
+
end
|
23
|
+
|
24
|
+
def load_command
|
25
|
+
instance.host_env.command('tar', '-xzf', '-', '-C', uploads_path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def clear_uploads
|
29
|
+
infom "Removing all files under #{uploads_path}..."
|
30
|
+
instance.host_env.command('find', uploads_path, '-mindepth', 1, '-delete').execute!
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'avm/stereotypes/postgresql/instance/data_unit'
|
4
|
+
|
3
5
|
module Avm
|
4
6
|
module Stereotypes
|
5
7
|
module Postgresql
|
@@ -9,6 +11,10 @@ module Avm
|
|
9
11
|
@connection_params = connection_params.with_indifferent_access
|
10
12
|
end
|
11
13
|
|
14
|
+
def data_unit
|
15
|
+
::Avm::Stereotypes::Postgresql::Instance::DataUnit.new(self)
|
16
|
+
end
|
17
|
+
|
12
18
|
def dump_command
|
13
19
|
env.command('pg_dump', '--no-privileges', '--clean', '--no-owner', *common_command_args)
|
14
20
|
.envvar('PGPASSWORD', password)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/data/instance/unit'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Stereotypes
|
7
|
+
module Postgresql
|
8
|
+
class Instance
|
9
|
+
class DataUnit < ::Avm::Data::Instance::Unit
|
10
|
+
EXTENSION = '.pgdump.gz'
|
11
|
+
|
12
|
+
before_load :clear_database
|
13
|
+
|
14
|
+
def dump_command
|
15
|
+
instance.dump_gzip_command
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_command
|
19
|
+
instance.psql_command.prepend(['gzip', '-d', '@ESC_|'])
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def clear_database
|
25
|
+
info 'Clearing database (Dropping all tables)...'
|
26
|
+
run_sql(drop_all_tables_sql).if_present { |v| run_sql(v) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def drop_all_tables_sql
|
30
|
+
"select 'drop table \"' || tablename || '\" cascade;' from pg_tables " \
|
31
|
+
"where schemaname = 'public';"
|
32
|
+
end
|
33
|
+
|
34
|
+
def run_sql(sql)
|
35
|
+
instance.psql_command_command(sql).execute!
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'active_support/core_ext/numeric/time'
|
4
4
|
require 'eac_ruby_utils/console/speaker'
|
5
5
|
require 'eac_ruby_utils/simple_cache'
|
6
|
+
require 'avm/data/package/dump'
|
6
7
|
|
7
8
|
module Avm
|
8
9
|
module Tools
|
@@ -31,10 +32,10 @@ module Avm
|
|
31
32
|
DOCUMENT
|
32
33
|
|
33
34
|
def run
|
34
|
-
if
|
35
|
-
|
35
|
+
if package_dump.runnable?
|
36
|
+
package_dump.run
|
36
37
|
else
|
37
|
-
warn(
|
38
|
+
warn(package_dump.cannot_run_reason)
|
38
39
|
end
|
39
40
|
success("Dump path: \"#{dump_path}\"")
|
40
41
|
dump_path
|
@@ -42,6 +43,10 @@ module Avm
|
|
42
43
|
|
43
44
|
private
|
44
45
|
|
46
|
+
def package_dump_uncached
|
47
|
+
context(:instance).data_package.dump(dump_path, existing: package_dump_existing)
|
48
|
+
end
|
49
|
+
|
45
50
|
def dump_path
|
46
51
|
options.fetch('--dump-path') || default_dump_path
|
47
52
|
end
|
@@ -50,58 +55,12 @@ module Avm
|
|
50
55
|
context(:instance).read_entry(DEFAULT_DUMP_PATH_ENTRY_SUFFIX)
|
51
56
|
end
|
52
57
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
def dump_expired?
|
62
|
-
return false unless dump_time.present?
|
63
|
-
|
64
|
-
dump_time >= DUMP_EXPIRE_TIME
|
65
|
-
end
|
66
|
-
|
67
|
-
def run_dump
|
68
|
-
download_dump
|
69
|
-
rotate_dump
|
70
|
-
move_download_to_final_dest
|
71
|
-
end
|
72
|
-
|
73
|
-
def download_dump
|
74
|
-
infom 'Downloading dump...'
|
75
|
-
dump_command.system!(output_file: download_path)
|
76
|
-
fatal_error "File \"#{download_path}\" not saved" unless ::File.exist?(download_path)
|
77
|
-
fatal_error "File \"#{download_path}\" is empty" if ::File.zero?(download_path)
|
78
|
-
end
|
79
|
-
|
80
|
-
def move_download_to_final_dest
|
81
|
-
::FileUtils.mv(download_path, dump_path)
|
82
|
-
end
|
83
|
-
|
84
|
-
def rotate_dump
|
85
|
-
return unless dump_exist?
|
86
|
-
|
87
|
-
info "Rotating \"#{dump_path}\"..."
|
88
|
-
::Avm::Files::Rotate.new(dump_path).run
|
89
|
-
end
|
90
|
-
|
91
|
-
def download_path_uncached
|
92
|
-
f = ::Tempfile.new('eac_rails_base0_data_dump')
|
93
|
-
path = f.path
|
94
|
-
f.close
|
95
|
-
f.unlink
|
96
|
-
path
|
97
|
-
end
|
98
|
-
|
99
|
-
def run_dump?
|
100
|
-
!dump_exist? || options.fetch('--rewrite') || dump_expired?
|
101
|
-
end
|
102
|
-
|
103
|
-
def dump_command
|
104
|
-
context(:instance).pg.dump_gzip_command
|
58
|
+
def package_dump_existing
|
59
|
+
if options.fetch('--rewrite')
|
60
|
+
::Avm::Data::Package::Dump::EXISTING_ROTATE
|
61
|
+
else
|
62
|
+
::Avm::Data::Package::Dump::EXISTING_ROTATE_EXPIRED
|
63
|
+
end
|
105
64
|
end
|
106
65
|
end
|
107
66
|
end
|
@@ -29,9 +29,7 @@ module Avm
|
|
29
29
|
return ::Dev::Result.error("Dump \"#{dump_path}\" does not exist") unless
|
30
30
|
::File.exist?(dump_path)
|
31
31
|
|
32
|
-
before_load
|
33
32
|
load_dump
|
34
|
-
fix_web_addresses
|
35
33
|
success("Dump loaded from \"#{dump_path}\"")
|
36
34
|
end
|
37
35
|
|
@@ -50,39 +48,18 @@ module Avm
|
|
50
48
|
|
51
49
|
def load_dump
|
52
50
|
info "Loading dump \"#{dump_path}\"..."
|
53
|
-
|
51
|
+
package_load.run
|
52
|
+
#::EacRubyUtils::Envs.local.command('cat', dump_path).pipe(load_command).execute!
|
54
53
|
end
|
55
54
|
|
56
55
|
def dump_instance_method
|
57
56
|
:dump_database
|
58
57
|
end
|
59
58
|
|
60
|
-
|
61
|
-
info 'Clearing database (Dropping all tables)...'
|
62
|
-
sql = run_sql(drop_all_tables_sql)
|
63
|
-
run_sql(sql) if sql.present?
|
64
|
-
end
|
65
|
-
|
66
|
-
def drop_all_tables_sql
|
67
|
-
"select 'drop table \"' || tablename || '\" cascade;' from pg_tables " \
|
68
|
-
"where schemaname = 'public';"
|
69
|
-
end
|
70
|
-
|
71
|
-
def run_sql(sql)
|
72
|
-
context(:instance).pg.psql_command_command(sql).execute!
|
73
|
-
end
|
74
|
-
|
75
|
-
def load_command
|
76
|
-
context(:instance).pg.psql_command.prepend(['gzip', '-d', '@ESC_|'])
|
77
|
-
end
|
59
|
+
private
|
78
60
|
|
79
|
-
def
|
80
|
-
|
81
|
-
run_sql(<<~SQL)
|
82
|
-
update wp_options
|
83
|
-
set option_value = '#{context(:instance).read_entry('url')}'
|
84
|
-
where option_name in ('siteurl', 'home')
|
85
|
-
SQL
|
61
|
+
def package_load_uncached
|
62
|
+
context(:instance).data_package.load(dump_path)
|
86
63
|
end
|
87
64
|
end
|
88
65
|
end
|
data/lib/avm/tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avm-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aranha-parsers
|
@@ -76,14 +76,14 @@ dependencies:
|
|
76
76
|
requirements:
|
77
77
|
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: '0.
|
79
|
+
version: '0.12'
|
80
80
|
type: :runtime
|
81
81
|
prerelease: false
|
82
82
|
version_requirements: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
84
|
- - "~>"
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version: '0.
|
86
|
+
version: '0.12'
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
88
|
name: filesize
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,6 +98,20 @@ dependencies:
|
|
98
98
|
- - ">="
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: minitar
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
type: :runtime
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
101
115
|
- !ruby/object:Gem::Dependency
|
102
116
|
name: rspec
|
103
117
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,6 +171,14 @@ files:
|
|
157
171
|
- exe/avm
|
158
172
|
- lib/avm.rb
|
159
173
|
- lib/avm/configs.rb
|
174
|
+
- lib/avm/data.rb
|
175
|
+
- lib/avm/data/instance.rb
|
176
|
+
- lib/avm/data/instance/package.rb
|
177
|
+
- lib/avm/data/instance/unit.rb
|
178
|
+
- lib/avm/data/package.rb
|
179
|
+
- lib/avm/data/package/dump.rb
|
180
|
+
- lib/avm/data/package/load.rb
|
181
|
+
- lib/avm/data/unit.rb
|
160
182
|
- lib/avm/files.rb
|
161
183
|
- lib/avm/files/rotate.rb
|
162
184
|
- lib/avm/git.rb
|
@@ -181,8 +203,10 @@ files:
|
|
181
203
|
- lib/avm/result.rb
|
182
204
|
- lib/avm/stereotypes.rb
|
183
205
|
- lib/avm/stereotypes/eac_wordpress_base0/instance.rb
|
206
|
+
- lib/avm/stereotypes/eac_wordpress_base0/uploads_data_unit.rb
|
184
207
|
- lib/avm/stereotypes/postgresql.rb
|
185
208
|
- lib/avm/stereotypes/postgresql/instance.rb
|
209
|
+
- lib/avm/stereotypes/postgresql/instance/data_unit.rb
|
186
210
|
- lib/avm/stereotypes/postgresql/instance_with.rb
|
187
211
|
- lib/avm/tools.rb
|
188
212
|
- lib/avm/tools/git.rb
|