Skip to content
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bac58df
sync
Sleepwalker86 Nov 27, 2025
b330d56
Update Samba upload to modern SMB2/SMB3 connection
Sleepwalker86 Nov 27, 2025
7192b8d
SMB-Upload überarbeitet: zuerst SMB2/3, bei Fehlschlag Fallback auf SMB1
Sleepwalker86 Dec 2, 2025
c41b5d9
Merge branch 'openWB:master' into update_smb_backup
Sleepwalker86 Dec 2, 2025
53bfd36
fix whitespace
Sleepwalker86 Dec 2, 2025
a53f90e
Merge branch 'update_smb_backup' of https://github.com/Sleepwalker86/…
Sleepwalker86 Dec 2, 2025
c630f42
fix Whitespace
Sleepwalker86 Dec 2, 2025
78c1849
Update packages/modules/backup_clouds/samba/backup_cloud.py
Sleepwalker86 Dec 3, 2025
3662337
Update packages/modules/backup_clouds/samba/backup_cloud.py
Sleepwalker86 Dec 3, 2025
b87ead6
Update packages/modules/backup_clouds/samba/backup_cloud.py
Sleepwalker86 Dec 3, 2025
623d603
Update packages/modules/backup_clouds/samba/backup_cloud.py
Sleepwalker86 Dec 3, 2025
dc2047a
Update packages/modules/backup_clouds/samba/backup_cloud.py
Sleepwalker86 Dec 3, 2025
c6c9d5f
Update packages/modules/backup_clouds/samba/backup_cloud.py
Sleepwalker86 Dec 3, 2025
2285e86
Merge branch 'openWB:master' into update_smb_backup
Sleepwalker86 Dec 3, 2025
0f00193
Delete .idea/.gitignore
Sleepwalker86 Dec 3, 2025
773b81c
Delete .idea/core.iml
Sleepwalker86 Dec 3, 2025
42ed570
Delete .idea/inspectionProfiles/Project_Default.xml
Sleepwalker86 Dec 3, 2025
2082ec2
Delete .idea/inspectionProfiles/profiles_settings.xml
Sleepwalker86 Dec 3, 2025
5e46581
Delete .idea/modules.xml
Sleepwalker86 Dec 3, 2025
2ee01a4
Delete .idea/vcs.xml
Sleepwalker86 Dec 3, 2025
583f008
Fallback korrigiert
Sleepwalker86 Dec 3, 2025
0fe0302
fix Zeile zu lang
Sleepwalker86 Dec 3, 2025
08c6b0d
Update packages/modules/backup_clouds/samba/backup_cloud.py
LKuemmel Dec 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 65 additions & 21 deletions packages/modules/backup_clouds/samba/backup_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,75 @@ def is_port_open(host: str, port: int):


def upload_backup(config: SambaBackupCloudConfiguration, backup_filename: str, backup_file: bytes) -> None:
conn = SMBConnection(config.smb_user, config.smb_password, os.uname()[1], config.smb_server, use_ntlm_v2=True)
found_invalid_chars = re.search(r'[\\\:\*\?\"\<\>\|]+', config.smb_path)
host_is_reachable = is_port_open(config.smb_server, 139)

if found_invalid_chars:
log.warning("Folgenden ungültige Zeichen im Pfad gefunden: {}".format(found_invalid_chars.group()))
log.warning("Sicherung nicht erfolgreich.")
send_file = False
else:
send_file = True
SMB_PORT_445 = 445
SMB_PORT_139 = 139

# Pfad prüfen
if re.search(r'[\\\:\*\?\"\<\>\|]+', config.smb_path):
raise Exception("Ungültige Zeichen im Pfad. Sicherung nicht erfolgreich.")

# ------------------------------------------------------------
# 1) SMB2/3 über Port 445 testen
# ------------------------------------------------------------
if is_port_open(config.smb_server, SMB_PORT_445):
conn = SMBConnection(
config.smb_user,
config.smb_password,
os.uname()[1],
config.smb_server,
use_ntlm_v2=True,
is_direct_tcp=True
)

if conn.connect(config.smb_server, SMB_PORT_445):
try:
log.info("SMB-Verbindung über Port 445 erfolgreich.")
full_file_path = f"{config.smb_path.rstrip('/')}/{backup_filename}"
log.info(f"Backup nach //{config.smb_server}/{config.smb_share}/{full_file_path}")

conn.storeFile(config.smb_share, full_file_path, io.BytesIO(backup_file))

return
except Exception as error:
raise Exception("Freigabe oder Unterordner existiert möglicherweise nicht. "+str(error).split('\n')[0])
finally:
conn.close()
else:
raise Exception("SMB-Verbindungsaufbau über Port 445 nicht möglich.")

if host_is_reachable and conn.connect(config.smb_server, 139) and send_file:
log.info("SMB Verbindungsaufbau erfolgreich.")
full_file_path = config.smb_path + backup_filename if config.smb_path is not None else backup_filename
log.info("Backup nach //" + config.smb_server + '/' + config.smb_share + '/' + full_file_path)
# ------------------------------------------------------------
# 2) Fallback: SMB1 über Port 139
# ------------------------------------------------------------
if not is_port_open(config.smb_server, SMB_PORT_139):
raise Exception(
f"Host {config.smb_server} und/oder Port {SMB_PORT_139} und {SMB_PORT_445} nicht erreichbar."
)

conn = SMBConnection(
config.smb_user,
config.smb_password,
os.uname()[1],
config.smb_server,
use_ntlm_v2=True
)

if conn.connect(config.smb_server, SMB_PORT_139):
try:
log.info("SMB Verbindungsaufbau über Port 139 erfolgreich.")
full_file_path = f"{config.smb_path.rstrip('/')}/{backup_filename}"
log.info(f"Backup nach //{config.smb_server}/{config.smb_share}/{full_file_path}")

conn.storeFile(config.smb_share, full_file_path, io.BytesIO(backup_file))
except Exception as error:
log.error(error.__str__().split('\n')[0])
log.error("Möglicherweise ist die Freigabe oder ein Unterordner nicht vorhanden.")
conn.close()
elif send_file:
log.warning("SMB Verbindungsaufbau fehlgeschlagen.")
elif not host_is_reachable:
log.warning("Host {} und/oder Port 139 nicht zu erreichen.".format(config.smb_server))
raise Exception(
"Möglicherweise ist die Freigabe oder ein Unterordner nicht vorhanden."
+ str(error).split("\n")[0]
)

finally:
conn.close()
else:
raise Exception("SMB Verbindungsaufbau über Port 139 fehlgeschlagen.")


def create_backup_cloud(config: SambaBackupCloud):
Expand Down