-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpve-move-disks.php
executable file
·65 lines (47 loc) · 1.47 KB
/
pve-move-disks.php
1
2
3
4
5
6
7
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
61
62
63
64
65
#!/usr/bin/php
<?php
require_once("pve-utils.php");
$args = PmUtils::options("d:s:t:");
$opts = PmUtils::getOpt($args);
if (!$opts || !isset($args['d'])) {
echo "Move disk to another storage or format - Usage:\n".
PmUtils::usage()."
-d dest storage (required)
-s source storage
-t target format (raw, qcow2, vmdk)
-R Only migrate running nodes
";
exit();
}
$dstorage = $args['d'];
$sstorage = "";
if (array_key_exists('s', $args)) {
$sstorage = $args['s'];
}
$format = "";
if (array_key_exists('t', $args)) {
$format = strtolower($args['t']);
}
if ($format && !in_array($format, ["raw", "qcow2", "vmdk"])) {
echo 'Format not "raw", "qcow2" or "vmdk"'."\n";
exit();
}
$pmutils = new PmUtils($opts);
if (!$pmutils->storageExists($dstorage)) {
echo "Could not find destination storage $dstorage or the storage does not contain images\n";
exit();
}
if ($sstorage && !$pmutils->storageExists($sstorage)) {
echo "Could not find source storage $sstorage or the storage does not contain images\n";
exit();
}
foreach ($pmutils->getAllDisks($sstorage)['disks'] as $disk) {
$regex = "";
if ($format) $regex ="\.$format.*";
if (preg_match("/^$dstorage.*$regex$/", $disk['content']) === 1) continue;
if (!$opts['dryrun']) $pmutils->delayTasks(1);
echo "\nMoving {$disk['disk']} - {$disk['content']} to $dstorage $format on {$disk['vmid']} : {$disk['vmname']}\n";
if ($opts['dryrun']) continue;
$pmutils->moveDisk($disk, $dstorage, $format);
}
?>