mirror of
				https://gitlab.sectorq.eu/jaydee/omv_backup.git
				synced 2025-10-30 10:01:11 +01:00 
			
		
		
		
	build
This commit is contained in:
		
							
								
								
									
										102
									
								
								omv_backup.py
									
									
									
									
									
								
							
							
						
						
									
										102
									
								
								omv_backup.py
									
									
									
									
									
								
							| @@ -19,54 +19,6 @@ import paramiko | |||||||
| import shutil | import shutil | ||||||
| import paho.mqtt.client as mqtt | import paho.mqtt.client as mqtt | ||||||
| #import numpy as np | #import numpy as np | ||||||
| logging.info(f"Start OMV Backup") |  | ||||||
| BROKER = 'mqtt.home.lan'       # e.g., 'mqtt.example.com' |  | ||||||
| PORT = 1883                          # Typically 8883 for secure MQTT |  | ||||||
| TOPIC = 'sectorq/backups/start' |  | ||||||
| USERNAME = 'jaydee' |  | ||||||
| PASSWORD = 'jaydee1' |  | ||||||
| USE_TLS = False                       # Set to False if not using TLS |  | ||||||
|  |  | ||||||
| # Define actions based on payload |  | ||||||
| def handle_payload(payload): |  | ||||||
|     payload = payload.lower() |  | ||||||
|     if payload == 'turn_on_light': |  | ||||||
|         logging.info("💡 Turning on the light...") |  | ||||||
|     elif payload == 'turn_off_light': |  | ||||||
|         logging.info("💡 Turning off the light...") |  | ||||||
|     elif payload == 'play_music': |  | ||||||
|         logging.info("🎵 Playing music...") |  | ||||||
|     else: |  | ||||||
|         logging.error(f"⚠️ Unknown command: {payload}") |  | ||||||
|  |  | ||||||
| # Callback when connected |  | ||||||
| def on_connect(client, userdata, flags, rc): |  | ||||||
|     if rc == 0: |  | ||||||
|         logging.info("✅ Connected securely to broker") |  | ||||||
|         client.subscribe(TOPIC) |  | ||||||
|         logging.info(f"📡 Subscribed to topic: {TOPIC}") |  | ||||||
|     else: |  | ||||||
|         logging.error(f"❌ Connection failed with code {rc}") |  | ||||||
|  |  | ||||||
| # Callback when a message is received |  | ||||||
| def on_message(client, userdata, msg): |  | ||||||
|     payload = msg.payload.decode() |  | ||||||
|     logging.info(f"📨 Received message: {payload} on topic: {msg.topic}") |  | ||||||
|     handle_payload(payload) |  | ||||||
|  |  | ||||||
| # MQTT client setup |  | ||||||
| client = mqtt.Client() |  | ||||||
| client.username_pw_set(USERNAME, PASSWORD) |  | ||||||
| client.on_connect = on_connect |  | ||||||
| client.on_message = on_message |  | ||||||
|  |  | ||||||
| # Use TLS for encrypted connection |  | ||||||
| if USE_TLS: |  | ||||||
|     client.tls_set()  # You can customize this with certs if needed |  | ||||||
|  |  | ||||||
| # Connect and loop forever |  | ||||||
| client.connect(BROKER, PORT, keepalive=60) |  | ||||||
| client.loop_forever() |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -182,6 +134,60 @@ except: | |||||||
|     client = mqtt_client.Client() |     client = mqtt_client.Client() | ||||||
| client.username_pw_set(mqtt_username, mqtt_password) | client.username_pw_set(mqtt_username, mqtt_password) | ||||||
|  |  | ||||||
|  | logging.info(f"Start OMV Backup") | ||||||
|  | BROKER = 'mqtt.home.lan'       # e.g., 'mqtt.example.com' | ||||||
|  | PORT = 1883                          # Typically 8883 for secure MQTT | ||||||
|  | TOPIC = 'sectorq/backups/start' | ||||||
|  | USERNAME = 'jaydee' | ||||||
|  | PASSWORD = 'jaydee1' | ||||||
|  | USE_TLS = False                       # Set to False if not using TLS | ||||||
|  |  | ||||||
|  | # Define actions based on payload | ||||||
|  | def handle_payload(payload): | ||||||
|  |     payload = payload.lower() | ||||||
|  |     if payload == 'turn_on_light': | ||||||
|  |         logging.info("💡 Turning on the light...") | ||||||
|  |     elif payload == 'turn_off_light': | ||||||
|  |         logging.info("💡 Turning off the light...") | ||||||
|  |     elif payload == 'play_music': | ||||||
|  |         logging.info("🎵 Playing music...") | ||||||
|  |     else: | ||||||
|  |         logging.error(f"⚠️ Unknown command: {payload}") | ||||||
|  |  | ||||||
|  | # Callback when connected | ||||||
|  | def on_connect(client, userdata, flags, rc): | ||||||
|  |     if rc == 0: | ||||||
|  |         logging.info("✅ Connected securely to broker") | ||||||
|  |         client.subscribe(TOPIC) | ||||||
|  |         logging.info(f"📡 Subscribed to topic: {TOPIC}") | ||||||
|  |     else: | ||||||
|  |         logging.error(f"❌ Connection failed with code {rc}") | ||||||
|  |  | ||||||
|  | # Callback when a message is received | ||||||
|  | def on_message(client, userdata, msg): | ||||||
|  |     payload = msg.payload.decode() | ||||||
|  |     logging.info(f"📨 Received message: {payload} on topic: {msg.topic}") | ||||||
|  |     handle_payload(payload) | ||||||
|  |  | ||||||
|  | # MQTT client setup | ||||||
|  | client = mqtt.Client() | ||||||
|  | client.username_pw_set(USERNAME, PASSWORD) | ||||||
|  | client.on_connect = on_connect | ||||||
|  | client.on_message = on_message | ||||||
|  |  | ||||||
|  | # Use TLS for encrypted connection | ||||||
|  | if USE_TLS: | ||||||
|  |     client.tls_set()  # You can customize this with certs if needed | ||||||
|  |  | ||||||
|  | # Connect and loop forever | ||||||
|  | client.connect(BROKER, PORT, keepalive=60) | ||||||
|  | client.loop_forever() | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| backups = { | backups = { | ||||||
|     "nas": { |     "nas": { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user