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!
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
774B

  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. def new_snapshot(base, fun, name):
  9. type_ = zfs_get_type(base)
  10. if type_ != 'snapshot':
  11. raise ValueError('Provided base dataset is not a snapshot')
  12. if '/' not in name:
  13. root = '/'.join(base.split('/')[:-1])
  14. name = root + '/' + name
  15. zfs_run(['zfs', 'clone', base, name])
  16. try:
  17. fun()
  18. zfs_run(['zfs', 'set', 'readonly=on', name])
  19. snap_name = name + '@1'
  20. zfs_run(['zfs', 'snapshot', snap_name])
  21. except:
  22. zfs_run(['zfs', 'destroy', '-f', name])
  23. raise
  24. return snap_name