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:
		| @@ -17,8 +17,59 @@ import fnmatch | |||||||
| import yaml | import yaml | ||||||
| import paramiko | import paramiko | ||||||
| import shutil | import shutil | ||||||
|  | import paho.mqtt.client as mqtt | ||||||
| #import numpy as np | #import numpy as np | ||||||
|  |  | ||||||
|  | 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() | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| file_path = os.path.realpath(__file__) | file_path = os.path.realpath(__file__) | ||||||
| dir_path = os.path.dirname(file_path) | dir_path = os.path.dirname(file_path) | ||||||
| VERSION="1.0.9" | VERSION="1.0.9" | ||||||
| @@ -218,7 +269,9 @@ if _STOP: | |||||||
|             continue |             continue | ||||||
|         cmnd = f"docker stop {c.split()[-1]}" |         cmnd = f"docker stop {c.split()[-1]}" | ||||||
|         status, running_containers = subprocess.getstatusoutput(cmnd) |         status, running_containers = subprocess.getstatusoutput(cmnd) | ||||||
| if _RESTORE: | def restore_job(): | ||||||
|  |     logging.info(f'starting restore job') | ||||||
|  |     return 0 | ||||||
|     logging.info("Starting Restore") |     logging.info("Starting Restore") | ||||||
|     print("Starting Restore") |     print("Starting Restore") | ||||||
|     now = datetime.datetime.now() |     now = datetime.datetime.now() | ||||||
| @@ -458,7 +511,9 @@ if _RESTORE: | |||||||
|         cmnd = "ssh root@amd.home.lan 'systemctl suspend &'" |         cmnd = "ssh root@amd.home.lan 'systemctl suspend &'" | ||||||
|         status, output = subprocess.getstatusoutput(cmnd) |         status, output = subprocess.getstatusoutput(cmnd) | ||||||
|  |  | ||||||
| if _BACKUP: | def backup_job(): | ||||||
|  |     logging.info(f'starting backup job') | ||||||
|  |     return 0 | ||||||
|     last = 1 |     last = 1 | ||||||
|     while True: |     while True: | ||||||
|         directory = '/backups/' |         directory = '/backups/' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user