Undo all file changes that happened between num_pre and num_post, leaving the files into the state of num_pre. .. warning:: If one of the files has changes after num_post, they will be overwritten The snapshots are used to determine the file list, but the current
(config="root", files=None, num_pre=None, num_post=None)
| 708 | |
| 709 | |
| 710 | def undo(config="root", files=None, num_pre=None, num_post=None): |
| 711 | """ |
| 712 | Undo all file changes that happened between num_pre and num_post, leaving |
| 713 | the files into the state of num_pre. |
| 714 | |
| 715 | .. warning:: |
| 716 | If one of the files has changes after num_post, they will be overwritten |
| 717 | The snapshots are used to determine the file list, but the current |
| 718 | version of the files will be overwritten by the versions in num_pre. |
| 719 | |
| 720 | You to undo changes between num_pre and the current version of the |
| 721 | files use num_post=0. |
| 722 | |
| 723 | CLI Example: |
| 724 | |
| 725 | .. code-block:: bash |
| 726 | |
| 727 | salt '*' snapper.undo |
| 728 | """ |
| 729 | pre, post = _get_num_interval(config, num_pre, num_post) |
| 730 | |
| 731 | changes = status(config, pre, post) |
| 732 | changed = set(changes.keys()) |
| 733 | requested = set(files or changed) |
| 734 | |
| 735 | if not requested.issubset(changed): |
| 736 | raise CommandExecutionError( |
| 737 | "Given file list contains files that are not present" |
| 738 | "in the changed filelist: {}".format(changed - requested) |
| 739 | ) |
| 740 | |
| 741 | cmdret = __salt__["cmd.run"]( |
| 742 | "snapper -c {} undochange {}..{} {}".format( |
| 743 | config, pre, post, " ".join(requested) |
| 744 | ) |
| 745 | ) |
| 746 | |
| 747 | try: |
| 748 | components = cmdret.split(" ") |
| 749 | ret = {} |
| 750 | for comp in components: |
| 751 | key, val = comp.split(":") |
| 752 | ret[key] = val |
| 753 | return ret |
| 754 | except ValueError as exc: |
| 755 | raise CommandExecutionError( |
| 756 | f"Error while processing Snapper response: {cmdret}" |
| 757 | ) |
| 758 | |
| 759 | |
| 760 | def _get_jid_snapshots(jid, config="root"): |
no test coverage detected