#------------------------------------------------------# # Script de sauvegarde # Auteur: Yohan Fresneau #------------------------------------------------------# import os, sys, ctypes, socket errorStatus = False ip = "172.16.57.4" port = 25555 def saveFile(): global errorStatus global ip global port errorStatus = False ip_samba = sys.argv[2] username = sys.argv[3] password = sys.argv[4] do = sys.argv[5] tmpsrc = sys.argv[6] src = "" tmp = False for x in sys.argv: if x == tmpsrc: tmp = True if tmp == True: src += x+" " try: serveur = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serveur.connect((ip,port)) serveur.send(b"Try_Connexion_Client") reponse = serveur.recv(2048).decode() if reponse == "Ok_Connexion": serveur.send(b"1") reponse = serveur.recv(2048).decode() if reponse == "Ok_Fichiers": serveur.send(ip_samba.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Ip": serveur.send(username.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_User": serveur.send(password.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Password": serveur.send(do.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Do": serveur.send(src.encode()) reponse = serveur.recv(2048).decode() if reponse == "Ok_Src": ctypes.windll.user32.MessageBoxW(0, "Demande de sauvegarde envoyer !", "Script de Sauvegarde", 0) serveur.close() else: serveur.close() ctypes.windll.user32.MessageBoxW(0, "Erreur de connexion ! Connexion refuser par le serveur !", "Script de Sauvegarde", 0) except: if errorStatus == False: errorStatus = True ctypes.windll.user32.MessageBoxW(0, "Erreur de connexion ! Impossible de contacter le serveur !", "Script de Sauvegarde", 0) serveur.close() def saveBD(): global errorStatus global ip global port errorStatus = False ip_samba = sys.argv[2] username = sys.argv[3] password = sys.argv[4] do = sys.argv[5] user = sys.argv[6] passwd = sys.argv[7] tmpbd = sys.argv[8] bd = "" tmp = False for x in sys.argv: if x == tmpbd: tmp = True if tmp == True: bd += x+" " try: serveur = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serveur.connect((ip,port)) serveur.send(b"Try_Connexion_Client") reponse = serveur.recv(2048).decode() if reponse == "Ok_Connexion": serveur.send(b"2") reponse = serveur.recv(2048).decode() if reponse == "Ok_BD": serveur.send(ip_samba.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Ip": serveur.send(username.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_User": serveur.send(password.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Password": serveur.send(do.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Do": serveur.send(user.encode()) reponse = serveur.recv(2048).decode() if reponse == "Ok_User": serveur.send(passwd.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Password": serveur.send(bd.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_DB": ctypes.windll.user32.MessageBoxW(0, "Demande de sauvegarde envoyer !", "Script de Sauvegarde", 0) serveur.close() else: serveur.close() ctypes.windll.user32.MessageBoxW(0, "Erreur de connexion ! Connexion refuser par le serveur !", "Script de Sauvegarde", 0) except: if errorStatus == False: errorStatus = True ctypes.windll.user32.MessageBoxW(0, "Erreur de connexion ! Impossible de contacter le serveur !", "Script de Sauvegarde", 0) serveur.close() def restoreFile(): global errorStatus global ip global port errorStatus = False ip_samba = sys.argv[2] username = sys.argv[3] password = sys.argv[4] do = sys.argv[5] tmpsrc = sys.argv[6] src = "" tmp = False for x in sys.argv: if x == tmpsrc: tmp = True if tmp == True: src += x+" " try: serveur = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serveur.connect((ip,port)) serveur.send(b"Try_Connexion_Client") reponse = serveur.recv(2048).decode() if reponse == "Ok_Connexion": serveur.send(b"3") reponse = serveur.recv(2048).decode() if reponse == "Ok_RF": serveur.send(ip_samba.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Ip": serveur.send(username.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_User": serveur.send(password.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Password": serveur.send(do.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Do": serveur.send(src.encode()) reponse = serveur.recv(2048).decode() if reponse == "Ok_Src": ctypes.windll.user32.MessageBoxW(0, "Demande de restauration envoyer !", "Script de Sauvegarde", 0) serveur.close() else: serveur.close() ctypes.windll.user32.MessageBoxW(0, "Erreur de connexion ! Connexion refuser par le serveur !", "Script de Sauvegarde", 0) except: if errorStatus == False: errorStatus = True ctypes.windll.user32.MessageBoxW(0, "Erreur de connexion ! Impossible de contacter le serveur !", "Script de Sauvegarde", 0) serveur.close() def restoreBD(): global errorStatus global ip global port errorStatus = False ip_samba = sys.argv[2] username = sys.argv[3] password = sys.argv[4] do = sys.argv[5] user = sys.argv[6] passwd = sys.argv[7] tmpbd = sys.argv[8] bd = "" tmp = False for x in sys.argv: if x == tmpbd: tmp = True if tmp == True: bd += x+" " try: serveur = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serveur.connect((ip,port)) serveur.send(b"Try_Connexion_Client") reponse = serveur.recv(2048).decode() if reponse == "Ok_Connexion": serveur.send(b"4") reponse = serveur.recv(2048).decode() if reponse == "Ok_RB": serveur.send(ip_samba.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Ip": serveur.send(username.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_User": serveur.send(password.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Password": serveur.send(do.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Do": serveur.send(user.encode()) reponse = serveur.recv(2048).decode() if reponse == "Ok_User": serveur.send(passwd.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_Password": serveur.send(bd.encode()) reponse = serveur.recv(2048).decode() if reponse == "OK_File": ctypes.windll.user32.MessageBoxW(0, "Demande de restauration envoyer !", "Script de Sauvegarde", 0) serveur.close() else: serveur.close() ctypes.windll.user32.MessageBoxW(0, "Erreur de connexion ! Connexion refuser par le serveur !", "Script de Sauvegarde", 0) except: if errorStatus == False: errorStatus = True ctypes.windll.user32.MessageBoxW(0, "Erreur de connexion ! Impossible de contacter le serveur !", "Script de Sauvegarde", 0) serveur.close() def error(): ctypes.windll.user32.MessageBoxW(0, "Erreur ! La sytaxe est incorrecte !", "Script de Sauvegarde", 0) print("Erreur ! La sytaxe est incorrecte !") print(" "+sys.argv[0]+" [-file, --file, -f, --f] ") print(" "+sys.argv[0]+" [-bd, --bd, -b, --b] <( --databases db_1 db_2 db_n [ou] -A [pour toutes les base] ) ou (db_votre_base --tables table_1 table_2 table_n)>") print(" "+sys.argv[0]+" [-restaurefile, --restaurefile, -rf, --rf] ") print(" "+sys.argv[0]+" [-restaurebd, --restaurebd, -rb, --rb] ") print(" "+sys.argv[0]+" [-help, --help, -h, --h]") def main(): global errorStatus errorStatus = False try: if (sys.argv[1] == "-f" or sys.argv[1] == "--f" or sys.argv[1] == "-file" or sys.argv[1] == "--file") and len(sys.argv) >= 6: saveFile() elif (sys.argv[1] == "-bd" or sys.argv[1] == "--bd" or sys.argv[1] == "-b" or sys.argv[1] == "--b") and len(sys.argv) >= 8: saveBD() elif (sys.argv[1] == "-rf" or sys.argv[1] == "--rf" or sys.argv[1] == "-restaurefile" or sys.argv[1] == "--restaurefile") and len(sys.argv) >= 6: restoreFile() elif (sys.argv[1] == "-rb" or sys.argv[1] == "--rb" or sys.argv[1] == "-restaurebd" or sys.argv[1] == "--restaurebd") and len(sys.argv) >= 8: restoreBD() elif sys.argv[1] == "-help" or sys.argv[1] == "--help" or sys.argv[1] == "-h" or sys.argv[1] == "--h": print(" "+sys.argv[0]+" [-file, --file, -f, --f] ") print(" "+sys.argv[0]+" [-bd, --bd, -b, --b] <( --databases db_1 db_2 db_n [ou] -A [pour toutes les base] ) ou (db_votre_base --tables table_1 table_2 table_n)>") print(" "+sys.argv[0]+" [-restaurefile, --restaurefile, -rf, --rf] ") print(" "+sys.argv[0]+" [-restaurebd, --restaurebd, -rb, --rb] ") else: error() except: if errorStatus == False: errorStatus = True error() main() #------------------------------------------------------# # Script de sauvegarde # Auteur: Yohan Fresneau #------------------------------------------------------#