-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathbtrfs_snapshot_post_migration.py
More file actions
83 lines (74 loc) · 3.27 KB
/
btrfs_snapshot_post_migration.py
File metadata and controls
83 lines (74 loc) · 3.27 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright (c) 2025 SUSE LLC. All rights reserved.
#
# This file is part of suse-migration-services.
#
# suse-migration-services is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# suse-migration-services is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with suse-migration-services. If not, see <http://www.gnu.org/licenses/>
#
import logging
# project
from suse_migration_services.defaults import Defaults
from suse_migration_services.logger import Logger
from suse_migration_services.command import Command
from suse_migration_services.exceptions import DistMigrationBtrfsSnapshotPostMigrationException
class BtrfsSnapshotPostMigration:
def __init__(self):
"""
Post-migration btrfs snapshot creation.
Creates a image of the system after the distribution migration .
"""
Logger.setup()
self.log = logging.getLogger(Defaults.get_migration_log_name())
self.root_path = Defaults.get_system_root_path()
def perform(self):
try:
self.log.info('Running Post-migration btrfs snapshot creation')
stat = Command.run(['stat', '-f', '-c', '%T', self.root_path])
if stat and stat.output.strip() == 'btrfs':
with open(
'/run/suse_migration_snapper_btrfs_pre_snapshot_number'
) as pre_snapshot_number_file:
pre_snapshot_number = pre_snapshot_number_file.read().strip()
if not pre_snapshot_number.isdigit():
message = f'Invalid snapshot number: {pre_snapshot_number}'
self.log.error(message)
raise ValueError(message)
Command.run(
[
'chroot',
self.root_path,
'snapper',
'--no-dbus',
'create',
'--type',
'single',
'--read-only',
'--cleanup-algorithm',
'number',
'--print-number',
'--userdata',
'important=yes',
'--description',
'after offline migration',
]
)
self.log.info('BTRFS post-migration snapshot creation completed successfully.')
else:
self.log.info('The root filesystem is not btrfs, skipping snapshot creation')
except Exception as issue:
message = 'BTRFS post-migration snapshot creation failed with: {}'
self.log.error(message.format(issue))
raise DistMigrationBtrfsSnapshotPostMigrationException(message.format(issue))
def main():
snapshot_post = BtrfsSnapshotPostMigration()
snapshot_post.perform()