Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-133973 / 25.04-RC.1 / Remove samba dataset snapshot on upgrade (by anodos325) #15574

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions src/middlewared/middlewared/plugins/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,37 +453,6 @@ async def get_update_location(self):
os.makedirs(path, exist_ok=True)
return path

@private
def take_systemdataset_samba4_snapshot(self):
basename = self.middleware.call_sync('systemdataset.config')['basename']
if basename is None:
self.logger.warning('System dataset is not available, not taking snapshot')
return

dataset = f'{basename}/samba4'

proc = subprocess.run(['zfs', 'list', '-t', 'snapshot', '-H', '-o', 'name', '-s', 'name', '-d', '1', dataset],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf8', errors='ignore')
if proc.returncode != 0:
self.logger.warning('Unable to list dataset %s snapshots: %s', dataset, proc.stderr)
return

snapshots = [s.split('@')[1] for s in proc.stdout.strip().splitlines()]
for snapshot in [s for s in snapshots if s.startswith('update--')][:-4]:
self.logger.info('Deleting dataset %s snapshot %s', dataset, snapshot)
subprocess.run(['zfs', 'destroy', f'{dataset}@{snapshot}'])

current_version = self.middleware.call_sync('system.version_short')
snapshot = f'update--{utc_now().strftime("%Y-%m-%d-%H-%M")}--{PRODUCT}-{current_version}'
subprocess.run(['zfs', 'snapshot', f'{dataset}@{snapshot}'])


async def post_update_hook(middleware):
is_ha = await middleware.call('failover.licensed')
if not is_ha or await middleware.call('failover.status') != 'BACKUP':
await middleware.call('update.take_systemdataset_samba4_snapshot')


async def setup(middleware):
await middleware.call('network.general.register_activity', 'update', 'Update')
middleware.register_hook('update.post_update', post_update_hook, sync=True)