Returns the differences between two snapshots config Configuration name. filename if not provided the showing differences between snapshots for all "text" files num_pre first snapshot ID to compare. Default is last snapshot num_post la
(config="root", filename=None, num_pre=None, num_post=None)
| 797 | |
| 798 | |
| 799 | def diff(config="root", filename=None, num_pre=None, num_post=None): |
| 800 | """ |
| 801 | Returns the differences between two snapshots |
| 802 | |
| 803 | config |
| 804 | Configuration name. |
| 805 | |
| 806 | filename |
| 807 | if not provided the showing differences between snapshots for |
| 808 | all "text" files |
| 809 | |
| 810 | num_pre |
| 811 | first snapshot ID to compare. Default is last snapshot |
| 812 | |
| 813 | num_post |
| 814 | last snapshot ID to compare. Default is 0 (current state) |
| 815 | |
| 816 | CLI Example: |
| 817 | |
| 818 | .. code-block:: bash |
| 819 | |
| 820 | salt '*' snapper.diff |
| 821 | salt '*' snapper.diff filename=/var/log/snapper.log num_pre=19 num_post=20 |
| 822 | """ |
| 823 | try: |
| 824 | pre, post = _get_num_interval(config, num_pre, num_post) |
| 825 | |
| 826 | files = changed_files(config, pre, post) |
| 827 | if filename: |
| 828 | files = [filename] if filename in files else [] |
| 829 | |
| 830 | subvolume = list_configs()[config]["SUBVOLUME"] |
| 831 | pre_mount = snapper.MountSnapshot(config, pre, False) if pre else subvolume |
| 832 | post_mount = snapper.MountSnapshot(config, post, False) if post else subvolume |
| 833 | |
| 834 | files_diff = dict() |
| 835 | for filepath in [filepath for filepath in files if not os.path.isdir(filepath)]: |
| 836 | |
| 837 | _filepath = filepath |
| 838 | if filepath.startswith(subvolume): |
| 839 | _filepath = filepath[len(subvolume) :] |
| 840 | |
| 841 | # Just in case, removing possible double '/' from the final file paths |
| 842 | pre_file = os.path.normpath(pre_mount + "/" + _filepath).replace("//", "/") |
| 843 | post_file = os.path.normpath(post_mount + "/" + _filepath).replace( |
| 844 | "//", "/" |
| 845 | ) |
| 846 | |
| 847 | if os.path.isfile(pre_file): |
| 848 | pre_file_exists = True |
| 849 | with salt.utils.files.fopen(pre_file) as rfh: |
| 850 | pre_file_content = [ |
| 851 | salt.utils.stringutils.to_unicode(_l) for _l in rfh.readlines() |
| 852 | ] |
| 853 | else: |
| 854 | pre_file_content = [] |
| 855 | pre_file_exists = False |
| 856 |
no test coverage detected