5
5
# Mysql Restore Command
7
class MysRestoreCommand < DataCommand
7
class MysRestoreCommand < CloudsqlRestoreCommand
11
include RootPrivileges
16
def mys_restore_command
17
"nice curl --silent --show-error --fail #{curl_token_option} #{target_uri_name} | tar --extract #{compression_tag} --directory #{data_area} ."
21
"nice curl -r0-3 --silent --show-error --fail #{curl_token_option} #{target_uri_name}"
24
def service_running_command
26
"systemctl is-active --quiet mysql",
27
"status mysql 2>/dev/null | grep -q running"
31
def stop_service_command
33
"systemctl stop mysql",
39
Syslog.info("#{self.class.name}: Zeroing MySQL data area - #{data_area}")
40
FileUtils.rm_r(data_area_file_list)
41
rescue SystemCallError => e
42
raise RuntimeError, "Failed to zero data area: #{e.message}"
45
def determine_compression
46
Syslog.debug("#{self.class.name}: Checking compression type")
47
magic = cmd(get_magic_command, "Fetching magic number", "failed to fetch magic number from #{target_uri_display_name}").to_s
49
when magic.unpack('V') == [0x184D2204]
50
Syslog.info("#{self.class.name}: Detected lz4 compressed archive")
51
@compression_tag = "-Ilz4"
52
when magic.unpack('n') == [0x1f8b]
53
Syslog.info("#{self.class.name}: Detected gzip compressed archive")
54
@compression_tag = "-z"
56
Syslog.info("#{self.class.name}: Assuming uncompressed archive")
61
attr_reader :compression_tag
64
Syslog.debug "Running restoration process"
65
if system(service_running_command)
66
run(stop_service_command, "stopped MySQL service", "failed to stop MySQL service")
70
run(mys_restore_command, "restored MySQL data area", "failed to restore database from #{target_uri_display_name}")
11
alias data_area mysql_data_area
12
alias service_name mysql_service_name