IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
919B

  1. #
  2. # Copyright (C) Stanislaw Adaszewski, 2020
  3. # License: GNU General Public License v3.0
  4. # URL: https://github.com/sadaszewski/focker
  5. # URL: https://adared.ch/focker
  6. #
  7. from .zfs import *
  8. from .misc import focker_lock, \
  9. focker_unlock
  10. def new_snapshot(base, fun, name):
  11. type_ = zfs_get_type(base)
  12. if type_ != 'snapshot':
  13. raise ValueError('Provided base dataset is not a snapshot')
  14. if '/' not in name:
  15. root = '/'.join(base.split('/')[:-1])
  16. name = root + '/' + name
  17. zfs_run(['zfs', 'clone', base, name])
  18. try:
  19. try:
  20. focker_unlock()
  21. fun()
  22. finally:
  23. focker_lock()
  24. zfs_run(['zfs', 'set', 'readonly=on', name])
  25. snap_name = name + '@1'
  26. zfs_run(['zfs', 'snapshot', snap_name])
  27. except:
  28. zfs_run(['zfs', 'destroy', '-f', name])
  29. raise
  30. return snap_name