dar-backup 0.6.8__py3-none-any.whl → 0.6.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dar_backup/__about__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.6.8"
1
+ __version__ = "0.6.9"
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ clean-log.py source code is here: https://github.com/per2jensen/dar-backup/tree/main/v2/src/dar_backup/clean-log.py
4
+ This script is part of dar-backup, a backup solution for Linux using dar and systemd.
5
+
6
+ Licensed under GNU GENERAL PUBLIC LICENSE v3, see the supplied file "LICENSE" for details.
7
+
8
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW,
9
+ not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See section 15 and section 16 in the supplied "LICENSE" file
11
+
12
+ This script can be used to remove (much of) the logged output from `dar`.
13
+ When `dar` verbose options are enabled, quite a lot of information is emitted.
14
+ """
15
+
16
+
17
+ import argparse
18
+ import re
19
+ import os
20
+ import sys
21
+
22
+ from . import __about__ as about
23
+ from dar_backup.config_settings import ConfigSettings
24
+
25
+ LICENSE = '''Licensed under GNU GENERAL PUBLIC LICENSE v3, see the supplied file "LICENSE" for details.
26
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27
+ See section 15 and section 16 in the supplied "LICENSE" file.'''
28
+
29
+ def clean_log_file(log_file_path, dry_run=False):
30
+ """Removes specific log lines from the given file using a memory-efficient streaming approach."""
31
+
32
+
33
+ if not os.path.isfile(log_file_path):
34
+ print(f"File '{log_file_path}' not found!")
35
+ sys.exit(1)
36
+
37
+ if not os.access(log_file_path, os.R_OK):
38
+ print(f"No read permission for '{log_file_path}'")
39
+ sys.exit(1)
40
+
41
+ if not os.access(log_file_path, os.W_OK):
42
+ print(f"Error: No write permission for '{log_file_path}'")
43
+ sys.exit(1)
44
+
45
+
46
+ if dry_run:
47
+ print(f"Performing a dry run on: {log_file_path}")
48
+
49
+ temp_file_path = log_file_path + ".tmp"
50
+
51
+ patterns = [
52
+ r"INFO\s*-\s*<File",
53
+ r"INFO\s*-\s*<Attributes",
54
+ r"INFO\s*-\s*</Directory",
55
+ r"INFO\s*-\s*<Directory",
56
+ r"INFO\s*-\s*</File",
57
+ r"INFO\s*-\s*Inspecting\s*directory",
58
+ r"INFO\s*-\s*Finished\s*Inspecting"
59
+ ]
60
+
61
+ try:
62
+ with open(log_file_path, "r", errors="ignore") as infile, open(temp_file_path, "w") as outfile:
63
+
64
+ for line in infile:
65
+ original_line = line # Store the original line before modifying it
66
+ matched = False # Track if a pattern is matched
67
+
68
+ for pattern in patterns:
69
+ if re.search(pattern, line): # Check if the pattern matches
70
+ if dry_run:
71
+ print(f"Would remove: {original_line.strip()}") # Print full line for dry-run
72
+ matched = True # Mark that a pattern matched
73
+ line = re.sub(pattern, "", line).strip() # Remove only matched part
74
+
75
+ if not dry_run and line: # In normal mode, only write non-empty lines
76
+ outfile.write(line.rstrip() + "\n")
77
+
78
+ if dry_run and matched:
79
+ continue # In dry-run mode, skip writing (since we’re just showing)
80
+
81
+
82
+ # Ensure the temp file exists before renaming
83
+ if not os.path.exists(temp_file_path):
84
+ open(temp_file_path, "w").close() # Create an empty file if nothing was written
85
+
86
+ os.replace(temp_file_path, log_file_path)
87
+ print(f"Successfully cleaned log file: {log_file_path}")
88
+
89
+ except Exception as e:
90
+ print(f"Error processing file: {e}")
91
+ sys.exit(1)
92
+
93
+
94
+
95
+ def main():
96
+ parser = argparse.ArgumentParser(
97
+ description="Clean dar-backup log file for `dar` output"
98
+ )
99
+ parser.add_argument(
100
+ "-f", "--file",
101
+ nargs="+",
102
+ type=str, help="Path(s) to the log file(s) that needs cleaning. Default is the log file specified in the configuration file."
103
+ )
104
+
105
+ parser.add_argument(
106
+ '-c', '--config-file',
107
+ type=str, help="Path to 'dar-backup.conf'",
108
+ default='~/.config/dar-backup/dar-backup.conf')
109
+
110
+ parser.add_argument(
111
+ "--dry-run",
112
+ action="store_true",
113
+ help="Show which lines would be removed without modifying the file."
114
+ )
115
+
116
+
117
+ parser.add_argument(
118
+ "-v", "--version",
119
+ action="version",
120
+ version=f"%(prog)s version {about.__version__}, {LICENSE}"
121
+ )
122
+
123
+ args = parser.parse_args()
124
+
125
+ config_settings = ConfigSettings(os.path.expanduser(args.config_file))
126
+
127
+ if not args.file:
128
+ args.file = [config_settings.logfile_location]
129
+
130
+ for file_path in args.file:
131
+ if not isinstance(file_path, (str, bytes, os.PathLike)):
132
+ print(f"Error: Invalid file path type: {file_path}")
133
+ sys.exit(1)
134
+
135
+ if not os.path.exists(file_path):
136
+ print(f"Error: Log file '{file_path}' does not exist.")
137
+ sys.exit(1)
138
+
139
+ if file_path.strip() == "":
140
+ print(f"Error: Invalid empty filename '{file_path}'.")
141
+ sys.exit(1)
142
+
143
+
144
+ # Run the log file cleaning function
145
+ for log_file in args.file:
146
+ clean_log_file(log_file, dry_run=args.dry_run)
147
+ print(f"Log file '{args.file}' has been cleaned successfully.")
148
+
149
+
150
+ if __name__ == "__main__":
151
+ main()
dar_backup/dar_backup.py CHANGED
@@ -322,7 +322,7 @@ def list_contents(backup_name, backup_dir, selection=None):
322
322
  stdout,stderr = process.stdout, process.stderr
323
323
  if process.returncode != 0:
324
324
  logger.error(f"Error listing contents of backup: '{backup_name}'")
325
- raise subprocess.CalledProcessError(str(process))
325
+ raise RuntimeError(str(process))
326
326
  for line in stdout.splitlines():
327
327
  if "[--- REMOVED ENTRY ----]" in line or "[Saved]" in line:
328
328
  print(line)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dar-backup
3
- Version: 0.6.8
3
+ Version: 0.6.9
4
4
  Summary: A script to do full, differential and incremental backups using dar. Some files are restored from the backups during verification, after which par2 redundancy files are created. The script also has a cleanup feature to remove old backups and par2 files.
5
5
  Project-URL: Homepage, https://github.com/per2jensen/dar-backup/tree/main/v2
6
6
  Project-URL: Changelog, https://github.com/per2jensen/dar-backup/blob/main/v2/Changelog.md
@@ -0,0 +1,14 @@
1
+ dar_backup/.darrc,sha256=-aerqivZmOsW_XBCh9IfbYTUvw0GkzDSr3Vx4GcNB1g,2113
2
+ dar_backup/__about__.py,sha256=42fbYUSZonpHevrA9hTI2EzfgLNO9LBK95poG3HeDEQ,21
3
+ dar_backup/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ dar_backup/clean_log.py,sha256=VXKA2BMyQmaC6R08Bq9a3wP3mczdFb_moy6HkL-mnF8,5176
5
+ dar_backup/cleanup.py,sha256=9yEdRR84XPtEvBGc2QfwGBQl2tdTPttjetHeiSc_TsM,11419
6
+ dar_backup/config_settings.py,sha256=CBMUhLOOZ-x7CRdS3vBDk4TYaGqC4N1Ot8IMH-qPaI0,3617
7
+ dar_backup/dar_backup.py,sha256=hDy7aXU-XiWOtW40Pxql441liNkSYKGU76eOwy8m7fU,32714
8
+ dar_backup/manager.py,sha256=HDa8eYF89QFhlBRR4EWRzzmswOW00S_w8ToZ5SARO_o,21359
9
+ dar_backup/util.py,sha256=SSSJYM9lQZfubhTUBlX1xDGWmCpYEF3ePARmlY544xM,11283
10
+ dar_backup-0.6.9.dist-info/METADATA,sha256=mqAzHZp_-X9pw8w77c4FA7QwXnKikkSodJ-oJnaFT3M,64610
11
+ dar_backup-0.6.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
12
+ dar_backup-0.6.9.dist-info/entry_points.txt,sha256=p6c4uQLjlTIVP1Od2iorGefrVUH0IWZdFRMl63mNaRg,164
13
+ dar_backup-0.6.9.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
14
+ dar_backup-0.6.9.dist-info/RECORD,,
@@ -1,4 +1,5 @@
1
1
  [console_scripts]
2
+ clean-log = dar_backup.clean_log:main
2
3
  cleanup = dar_backup.cleanup:main
3
4
  dar-backup = dar_backup.dar_backup:main
4
5
  manager = dar_backup.manager:main
@@ -1,13 +0,0 @@
1
- dar_backup/.darrc,sha256=-aerqivZmOsW_XBCh9IfbYTUvw0GkzDSr3Vx4GcNB1g,2113
2
- dar_backup/__about__.py,sha256=qbWTdDuFyvScwNj95KArnOcQph9tiLZZ8rgNJYlJ4AE,21
3
- dar_backup/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- dar_backup/cleanup.py,sha256=9yEdRR84XPtEvBGc2QfwGBQl2tdTPttjetHeiSc_TsM,11419
5
- dar_backup/config_settings.py,sha256=CBMUhLOOZ-x7CRdS3vBDk4TYaGqC4N1Ot8IMH-qPaI0,3617
6
- dar_backup/dar_backup.py,sha256=VbpyiCnoVvJuMWS7LO9wo8WIcDegCPVjb5Q7xN9J9Gg,32731
7
- dar_backup/manager.py,sha256=HDa8eYF89QFhlBRR4EWRzzmswOW00S_w8ToZ5SARO_o,21359
8
- dar_backup/util.py,sha256=SSSJYM9lQZfubhTUBlX1xDGWmCpYEF3ePARmlY544xM,11283
9
- dar_backup-0.6.8.dist-info/METADATA,sha256=U3iy7Gzz-D6p5UePy0VLzX2lNbELs0teKBEZXr-sSqc,64610
10
- dar_backup-0.6.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
- dar_backup-0.6.8.dist-info/entry_points.txt,sha256=x9vnW-JEl8mpDJC69f_XBcn0mBSkV1U0cyvFV-NAP1g,126
12
- dar_backup-0.6.8.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
13
- dar_backup-0.6.8.dist-info/RECORD,,