Class: Snapback::App::Rollback

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/snapback/app/rollback.rb

Instance Method Summary collapse

Instance Method Details

#goObject



8
9
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/snapback/app/rollback.rb', line 8

def go
  volume_group_name = "#{$config['lvm']['volume_group']}"
  logical_volume_name = "#{$config['lvm']['prefix_database']}-#{$options[:database]}"
  mount_dir = get_mount_dir $options[:database]
  mysql_data_dir = $database.get_data_dir

  # Flush the MySQL Logs
  exec_flush

  # Stop the MySQL Server
  $database.server_stop

  on_rollback lambda {
    $database.server_start
  }

  # Remove the symbolic link
  exec_unlink "#{mysql_data_dir}/#{$options[:database]}", mount_dir

  # Unmount the logical volume
  exec_unmount "/dev/#{volume_group_name}/#{logical_volume_name}", mount_dir

  # Deactivate the logical volume
  exec_deactivate "/dev/#{volume_group_name}/#{logical_volume_name}"

  # Merge the old logical volume into the new one
  # lvconvert --merge /dev/{vgName}/backup-{dbName}
  run "Merging the snapshot into the live logical volume",
    "lvconvert --merge /dev/#{volume_group_name}/#{$config['lvm']['prefix_backup']}-#{$options[:database]}"

  # Active the master drive
  # lvchange -ay /dev/{vgName}/mysql-{dbName}
  exec_activate "/dev/#{volume_group_name}/#{logical_volume_name}"

  # Mount the logical volume
  exec_mount "/dev/#{volume_group_name}/#{logical_volume_name}", mount_dir

  # Symbolic-link the MySQL data directory to the new logical volume
  exec_link "#{mysql_data_dir}/#{$options[:database]}", mount_dir

  # Change the permissions & ownership to MySQL 
  # chown -R mysql:mysql {mysql-data-dir}/{dbName}/
  # chown -R mysql:mysql /mnt/mysql/{dbName}/
  exec_chown "#{mysql_data_dir}/#{$options[:database]}"
  exec_chown "#{mount_dir}"

  # Start the MySQL Server
  $database.server_start

  on_rollback lambda {
    $database.server_stop
  }
end