Skip to content

Commit 78bce77

Browse files
committed
Support for rsync logging feature. EEsync logger improved. Rsync params moved to GeneralSettings. Other improvements.
1 parent f1b10cd commit 78bce77

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed

GeneralSettings.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# General settings. Adjust these to your needs.
22

33
runner = {
4+
# Command runner (OS Exec) settings.
45

56
# Prints the external (backup) commands that are executed on your OS.
67
# Asks for confirmation before running the command.
@@ -9,6 +10,7 @@
910
}
1011

1112
logger = {
13+
# Logger settings.
1214

1315
# Choose the logging method.
1416
# Available methods - uncomment one:
@@ -21,3 +23,37 @@
2123
# Blank value ("") means that logs will be saved in application directory ("./SavedLogs").
2224
"custom_log_dir_path": ""
2325
}
26+
27+
sync_rsync = {
28+
# Rsync settings and parameters.
29+
# Please make sure that you know what you're doing.
30+
# Options below will affect the file-synchronization process.
31+
# It is recommended for you to check following before you change anything in this section:
32+
# - rsync man pages: `https://linux.die.net/man/1/rsync`, `https://linux.die.net/man/5/rsyncd.conf`
33+
# - SyncProvider module in this project: `Src/Service/SyncProvider.py`
34+
35+
# Base parameters that are provided for the rsync.
36+
"rsync_base_params": [
37+
"-ah", "--delete"
38+
],
39+
40+
# ----
41+
42+
# Rsync has a nice logging feature ('--log-file' parameter).
43+
# Here, you can decide if you would like to use it or not.
44+
# Possible values: "True" or "False".
45+
# NOTE: Value if this setting a will also enable (or disable) other logging settings ("rsync_logging_*").
46+
"rsync_logging_enabled": True,
47+
48+
# Below you may define extra parameters for the logging feature.
49+
"rsync_logging_extra_params": [
50+
"--log-file-format=\"[%t] [%p] %o %m %f %l\""
51+
],
52+
53+
# ----
54+
55+
# Parameters that are added only if dry run mode is selected.
56+
"rsync_dry_run_params": [
57+
"--dry-run"
58+
]
59+
}

Src/EESync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class EESync:
13-
__version = '0.9.0'
13+
__version = '0.9.1'
1414

1515
sync_service = SyncProvider()
1616
crypt_service = CryptProvider()

Src/IO/Logger.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ def init(cls):
2828
else:
2929
cls.__log_dir = default_logs_directory
3030

31+
@classmethod
32+
def get_log_path(cls):
33+
"""
34+
Returns the application log directory.
35+
"""
36+
return cls.__log_dir
37+
3138
@classmethod
3239
def log(cls, text: str, log_level: str = None):
3340
"""

Src/Service/CommandRunner.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def gen_run_report(exec_command, stdout, stderr) -> str:
7575
"""
7676
Generates formatted string from command output.
7777
"""
78+
if stdout is None:
79+
stdout = str(f"{stdout} - no output or output disabled.\n")
80+
if stderr is None:
81+
stderr = str(f"{stderr} - no output or output disabled.\n")
7882
return str(f"--- STDOUT: {exec_command}: ---\n"
7983
+ str(stdout)
8084
+ f"--- STDERR: {exec_command}: ---\n"

Src/Service/CryptProvider.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import re
4+
import time
45
from functools import wraps
56

67
from Src.Common.BackupAction import BackupAction
@@ -67,6 +68,11 @@ def __unmount_encfs(self):
6768
print("... skipped - already unmounted!")
6869
return
6970

71+
# It is very likely that the target is still busy.
72+
# Sleep is surely a bad solution, but for now - it's enough.
73+
# TODO: check if target is busy, get rid of sleep()
74+
time.sleep(10.0)
75+
7076
which_result = self.os_exec(["which", "umount"], silent=True)
7177
umount_binary = str(which_result.stdout).strip()
7278
exec_command: list = [umount_binary, self.config.encfs_decryption_dir]

Src/Service/SyncProvider.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import os
44
import re
5+
from datetime import datetime
56

7+
import GeneralSettings
68
from Src.Common.BackupAction import BackupAction
79
from Src.Config.ConfigEntry import ConfigEntry
810
from Src.IO.Logger import Logger
@@ -82,16 +84,30 @@ def __exec_rsync(self, source_dir: str, target_dir: str, dry_run: bool):
8284
raise SystemExit("Error! Not a directory: " + path)
8385

8486
# prepare the command
85-
rsync_base_params: list = [
86-
"-avh", "--delete"
87-
]
87+
rsync_settings = GeneralSettings.sync_rsync
88+
rsync_base_params: list = rsync_settings['rsync_base_params']
89+
8890
if dry_run:
89-
rsync_base_params += ["--dry-run"]
91+
rsync_base_params += rsync_settings["rsync_dry_run_params"]
92+
93+
if rsync_settings["rsync_logging_enabled"]:
94+
# rsync logging - prepare the path
95+
current_date = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
96+
log_dir = Logger.get_log_path()
97+
rsync_log_path = log_dir + f"/rsync_{current_date}.log"
98+
if not os.path.isdir(log_dir) or os.path.isfile(rsync_log_path):
99+
raise SystemExit('Error! Rsync logging paths misconfigured!')
100+
101+
# rsync logging - log to a file
102+
rsync_base_params += [f"--log-file={rsync_log_path}"]
103+
104+
# rsync logging - extra params
105+
rsync_base_params += rsync_settings["rsync_logging_extra_params"]
90106

91107
exec_command: list = [self.binary_path] + rsync_base_params + [source_dir, target_dir]
92108

93109
# run the command
94-
rsync_result = self.os_exec(exec_command, confirmation_required=True)
110+
rsync_result = self.os_exec(exec_command, confirmation_required=True, capture_output=False)
95111

96112
# save the report
97113
run_report = self.gen_run_report(exec_command, rsync_result.stdout, rsync_result.stderr)

0 commit comments

Comments
 (0)