This repository was archived by the owner on Apr 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
169 lines (143 loc) · 7.26 KB
/
Copy pathmain.py
File metadata and controls
169 lines (143 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import os
import shutil
import tkinter as tk
from tkinter import filedialog, messagebox
import schedule
import time
from threading import Thread
from datetime import datetime
# Language elements
LANGUAGES = {
'hu': {
'source_label': 'Forrás mappa:',
'destination_label': 'Cél mappa:',
'browse': 'Tallózás',
'manual_backup': 'Manuális mentés',
'start_schedule': '12 óránkénti mentés indítása',
'success': 'Sikeresen elmentve ide:',
'error': 'Hiba történt a mentés során:',
'source_error': 'A forrás mappa nem létezik!',
'destination_error': 'A cél mappa nem létezik, vagy nem elérhető! Amennyiben szervert vagy NAS rendszert használd, ellenőrizd annak elérhetőségét!',
'schedule_started': '12 óránkénti mentés elindítva!',
},
'en': {
'source_label': 'Source folder:',
'destination_label': 'Destination folder:',
'browse': 'Browse',
'manual_backup': 'Manual Backup',
'start_schedule': 'Start 12-hour scheduled backup',
'success': 'Successfully backed up to:',
'error': 'Error occurred during backup:',
'source_error': 'Source folder does not exist!',
'destination_error': 'The target folder does not exist or is not available! If you use a server or NAS system, check its availability!',
'schedule_started': '12-hour scheduled backup started!',
},
'de': {
'source_label': 'Quellordner:',
'destination_label': 'Zielordner:',
'browse': 'Durchsuchen',
'manual_backup': 'Manuelle Sicherung',
'start_schedule': 'Starten Sie die 12-Stunden-Sicherung',
'success': 'Erfolgreich gesichert:',
'error': 'Während der Sicherung ist ein Fehler aufgetreten:',
'source_error': 'Quellordner existiert nicht!',
'destination_error': 'Der Zielordner existiert nicht oder ist nicht verfügbar! Wenn Sie einen Server oder ein NAS-System nutzen, prüfen Sie dessen Verfügbarkeit!',
'schedule_started': '12-Stunden-Plan-Backup gestartet!',
}
}
class BackupApp:
def __init__(self, root):
self.root = root
self.root.title("MSC Backup")
# Source & Destination folder variables
self.source_folder = tk.StringVar()
self.destination_folder = tk.StringVar()
self.language = tk.StringVar(value='en') # Default Language
# Translation elements
self.translations = LANGUAGES[self.languages.get()]
# GUI elements
self.language_selector = tk.OptionMenu(root, self.language, *LANGUAGES.keys(), command=self.update_language)
self.language_selector.grid(row=0, column=1, padx=10, pady=10)
self.source_label = tk.Label(root, text=self.translations['source_label'])
self.source_label.grid(row=1, column=0, padx=10, pady=10)
self.source_entry = tk.Entry(root, textvariable=self.source_folder, width=40)
self.source_entry.grid(row=1, column=1, padx=10)
self.source_button = tk.Button(root, text=self.translations['browse'], command=self.select_source_folder)
self.source_button.grid(row=1, column=2, padx=10)
self.destination_label = tk.Label(root, text=self.translations['destination_label'])
self.destination_label.grid(row=2, column=0, padx=10, pady=10)
self.destination_entry = tk.Entry(root, textvariable=self.destination_folder, width=40)
self.destination_entry.grid(row=2, column=1, padx=10)
self.destination_button = tk.Button(root, text=self.translations['browse'],command=self.select_destination_folder)
self.destination_button.grid(row=2, column=2, padx=10)
self.manual_backup_button = tk.Button(root, text=self.translations['manual_backup'], command=self.manual_backup)
self.manual_backup_button.grid(row=3, column=0, columnspan=3, pady=10)
self.schedule_button = tk.Button(root, text=self.translations['start_schedule'], command=self.start_scheduled_backup)
self.schedule_button.grid(row=4, column=0, columnspan=3, pady=10)
def update_language(self, event=None):
"""Frissíti a felület szövegeit a kiválasztott nyelv szerint."""
self.translations = LANGUAGES[self.language.get()]
# Szövegek frissítése
self.source_label.config(text=self.translations['source_label'])
self.destination_label.config(text=self.translations['destination_label'])
self.source_button.config(text=self.translations['browse'])
self.destination_button.config(text=self.translations['browse'])
self.manual_backup_button.config(text=self.translations['manual_backup'])
self.schedule_button.config(text=self.translations['start_schedule'])
def select_source_folder(self):
folder_selected = filedialog.askdirectory()
self.source_folder.set(folder_selected)
def select_destination_folder(self):
folder_selected = filedialog.askdirectory()
self.destination_folder.set(folder_selected)
def manual_backup(self):
source = self.source_folder.get()
destination = self.destination_folder.get()
if not os.path.exists(source):
messagebox.showerror("Error", self.translations['source_error'])
return
if not os.path.exists(destination):
messagebox.showerror("Error", self.translations['destination_error'])
return
try:
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
destination_path = os.path.join(destination, f"backup_{timestamp}")
shutil.copytree(source, destination_path)
messagebox.showinfo("Success", f"{self.translations['success']} {destination_path}")
except Exception as e:
messagebox.showerror("Error", f"{self.translations['error']} {e}")
def start_scheduled_backup(self):
source = self.source_folder.get()
destination = self.destination_folder.get()
if not os.path.exists(source) or not os.path.exists(destination):
messagebox.showerror("Error", self.translations['source_error'])
return
# Scheduled backup every 12-hour
schedule.every(12).hours.do(self.scheduled_backup)
# Start background thread for scheduled tasks
t = Thread(target=self.run_scheduler)
t.daemon = True
t.start()
messagebox.showinfo("Schedule", self.translations['schedule_started'])
def scheduled_backup(self):
source = self.source_folder.get()
destination = self.destination_folder.get()
if os.path.exists(source) and os.path.exists(destination):
try:
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
destination_path = os.path.join(destination, f"backup_{timestamp}")
shutil.copytree(source, destination_path)
print(f"Sikeres mentés: {destination_path}")
except Exception as e:
print(f"{self.translations['error']} {e}")
else:
print(self.translations['source_error'])
def run_scheduler(self):
while True:
schedule.run_pending()
time.sleep(60) # Checks in every minute
# Main program
if __name__ == "__main__":
root = tk.Tk()
app = BackupApp(root)
root.mainloop()