-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebase.py
63 lines (51 loc) · 1.88 KB
/
rebase.py
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
from backup import Backup
class Rebase(Backup):
""" Rebase and commit all images inside VM's full backup """
def __init__(self, vm_name):
super().__init__(vm_name)
self.images = self.sort_images()
def validate(self):
super().images_validate()
if "full" in self.images[-1]:
self.error('Error: No incremental images found, nothing to commit')
def run(self):
self.validate()
idx = len(self.images) - 1
for image in reversed(self.images):
idx = idx - 1
if self.images.index(image) == 0 or 'full' in image:
print('Rollback of latest [FULL]<-[INC] chain complete\n')
break
print('"%s/%s" is based on "%s/%s"' % (
self.current_backup_path,
self.images[idx],
self.current_backup_path,
image
))
# before rebase we check consistency of file
cmd_check = 'sudo qemu-img check %s/%s' % (
self.current_backup_path,
image
)
print(cmd_check)
self.run_command(cmd_check, False)
cmd_rebase = 'sudo qemu-img rebase -b "%s/%s" "%s/%s"' % ( # -u
self.current_backup_path,
self.images[idx],
self.current_backup_path,
image,
)
print(cmd_rebase)
self.run_command(cmd_rebase, False)
cmd_commit = 'sudo qemu-img commit "%s/%s"' % (
self.current_backup_path,
image
)
print(cmd_commit)
self.run_command(cmd_commit, False)
cmd_remove = 'sudo rm %s/%s' % (
self.current_backup_path,
image
)
print(cmd_remove + '\n')
self.run_command(cmd_remove, False)