User Tools

Site Tools


cloudstack:unerase_vm

при удалении виртуалки в базе происходит несколько изменений, а именно:

  1. в таблице vm_instance меняются state,removed
  2. в таблице nics меняются state,removed
  3. в таблице user_ip_address обнуляются account_id,domain_id,allocated, меняется state
  4. в таблице volumes меняются state,removed

Кроме этого еще производится куча апдейтов по ресурсам, но это не сильно критично. Попробуем восстановить виртуалку, которая называлась i-2-1406-VM

mysql> select instance_name,id,state,private_ip_address, removed  from vm_instance where instance_name='i-2-1406-VM';
+---------------+------+-----------+--------------------+---------------------+
| instance_name | id   | state     | private_ip_address | removed             |
+---------------+------+-----------+--------------------+---------------------+
| i-2-1406-VM   | 1406 | Expunging | 185.15.185.46      | 2014-08-27 11:49:04 |
+---------------+------+-----------+--------------------+---------------------+
1 row in set (0.00 sec)

смотрим, свободен ли адрес, который ей принадлежал:

mysql> select public_ip_address,account_id,domain_id,allocated,vm_id,state,network_id  from user_ip_address WHERE public_ip_address='185.15.185.46';
+-------------------+------------+-----------+-----------+-------+-------+------------+
| public_ip_address | account_id | domain_id | allocated | vm_id | state | network_id |
+-------------------+------------+-----------+-----------+-------+-------+------------+
| 185.15.185.46     |       NULL |      NULL | NULL      |  NULL | Free  |       NULL |
+-------------------+------------+-----------+-----------+-------+-------+------------+
1 row in set (0.00 sec)

Смотрим на сетевуху:

mysql> select ip4_address,state,removed from nics WHERE nics.ip4_address='185.15.185.46' and instance_id=1406;
+---------------+--------------+---------------------+
| ip4_address   | state        | removed             |
+---------------+--------------+---------------------+
| 185.15.185.46 | Deallocating | 2014-08-27 11:49:02 |
+---------------+--------------+---------------------+
1 row in set (0.00 sec)

Смотрим на диски:

mysql>  select pool_id,path,removed,state from volumes WHERE instance_id=1406;
+---------+--------------------------------------+---------------------+----------+
| pool_id | path                                 | removed             | state    |
+---------+--------------------------------------+---------------------+----------+
|       2 | b6faf22b-1b4a-4256-9ed1-8536dad028c6 | 2014-08-27 11:49:04 | Expunged |
+---------+--------------------------------------+---------------------+----------+
1 row in set (0.00 sec)

Пробуем все вернуть:

1. апдейтим таблицу vm_instance

mysql> update vm_instance set state='Stopped' where instance_name='i-2-1406-VM';
Query OK, 1 row affected (0.07 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql> update vm_instance set removed=NULL where instance_name='i-2-1406-VM';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

2. возвращаем адрес виртуалке. Перед этим надо узнать domainid и account_id

mysql> select account_id,domain_id from vm_instance where instance_name='i-2-1406-VM';
+------------+-----------+
| account_id | domain_id |
+------------+-----------+
|          2 |         1 |
+------------+-----------+
1 row in set (0.01 sec)
 
mysql> update user_ip_address set account_id=2 WHERE public_ip_address='185.15.185.46';
Query OK, 1 row affected (0.47 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql> update user_ip_address set domain_id=1 WHERE public_ip_address='185.15.185.46';
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql> update user_ip_address set allocated=now() WHERE public_ip_address='185.15.185.46';
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql> update user_ip_address set state='Allocated' WHERE public_ip_address='185.15.185.46';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

3. возврашаем сетевой интерфейс:

mysql> update nics set state='Reserved' WHERE nics.ip4_address='185.15.185.46' and instance_id=1406;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql> update nics set removed=NULL WHERE nics.ip4_address='185.15.185.46' and instance_id=1406;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

4. возврашаем volume:

mysql> update volumes set removed=NULL WHERE instance_id=1406;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql> update volumes set state='Ready' WHERE instance_id=1406;
Query OK, 1 row affected (0.16 sec)
Rows matched: 1  Changed: 1  Warnings: 0

5. идем на хранилку и ищем снепшот диска (в данном примере это файл b6faf22b-1b4a-4256-9ed1-8536dad028c6 на GIGO1), кладем его в каталог:

[email protected]:~# cp -a  /GIGO1/p1/.zfs/snapshot/backupsnapshot/b6faf22b-1b4a-4256-9ed1-8536dad028c6 /GIGO1/p1/

6. стартуем виртуалку из вебморды

cloudstack/unerase_vm.txt · Last modified: 2014/08/27 13:17 by slayer