Code : Tout sélectionner
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.2.12.1
Author: SurPriseS
Script Function:
Sauvegarde automatique via commande SCP
#ce ----------------------------------------------------------------------------
#include <Process.au3>
#include <GUIConstants.au3>
#include <Date.au3>
;$variable
$sync_ok = 0
Global $combo_1
Global $cle_usb
Global $lecteur
; GUI
GuiCreate ( " Backup facture " , 370 , 230 ) ; fenêtre principale
GUISetState ( @SW_SHOW )
GUICtrlCreateGroup ( " Synchro " , 10 , 10 , 350 , 100 ) ; groupe synchronisation
$Button_synchro = GUICtrlCreateButton ( " Synchronisation " , 20 , 30 , 100 ) ; bouton synchronisation
GUICtrlCreateLabel( "Synchronisation : ",130,35)
GUICtrlCreateGroup ( " Clé USB " , 10 , 120 , 350 , 100 )
$label_synchro = GUICtrlCreateLabel("NOK",220,35)
GuiCtrlSetColor ( $label_synchro , 0xFF0000 ) ;rouge
list_lecteur()
$Button_backup = GUICtrlCreateButton ( " Backup " , 20 , 140 , 100 ) ; bouton synchronisation
While 1
$msg = GUIGetMsg ( )
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
;synchronisation
Case $msg = $Button_synchro
synchro()
;backup
Case $msg = $Button_backup
backup()
EndSelect
WEnd
; - - - - - - - - - - - - - - - - - - - - - Fonctions
; - - - - - - - - - - Synchronisation
Func synchro()
_RunDOS("winscp /console /script=maj.txt login:password@adresseip")
$label_synchro = GUICtrlCreateLabel("OK ",220,35)
GuiCtrlSetColor ( $label_synchro , 0x1eff00 ) ;vert
last_file_back()
last_file_script()
$sync_ok = 1
EndFunc
; - - - - - - - - - - Liste des lecteurs
Func list_lecteur()
$var = DriveGetDrive( "REMOVABLE" );"ALL", "CDROM", "REMOVABLE", "FIXED", "NETWORK", "RAMDISK", or "UNKNOWN"
If NOT @error Then
;MsgBox(4096,"", "Found " & $var[0] & " drives")
For $i = 1 to $var[0]
;MsgBox(4096,"Drive " & $i, $var[$i])
$lecteur = $var[$i] &"|" &$lecteur
Next
Else
$label_cle = GUICtrlCreateLabel("PAS DE CLE USB DETECTEE",130,145)
EndIf
$combo_1 = GUICtrlCreateCombo("Clé USB", 130, 142,100)
$combo_2 = GUICtrlSetData(-1, $lecteur, "Clé USB")
EndFunc
; - - - - - - - - - - Backup
Func backup()
if $sync_ok = 1 then
$cle_usb = GUICtrlRead($combo_1)
if $cle_usb = "Clé USB" then
MsgBox(54,"Erreur","Selectionner un lecteur avant.")
Else
$chemin = $cle_usb & "\saveqle\"
DirRemove($chemin,1)
DirCreate($chemin)
FileCopy($fichierplusrecent1,$chemin & $fichierplusrecent1,1)
$label_copy1 = GUICtrlCreateLabel("OK ",120,175)
GUICtrlCreateLabel("Backup fichier 1 : ",20,175)
GuiCtrlSetColor ( $label_copy1 , 0x1eff00 ) ;vert
FileCopy($fichierplusrecent2,$chemin & $fichierplusrecent2,1)
$label_copy2 = GUICtrlCreateLabel("OK ",120,195)
GUICtrlCreateLabel("Backup fichier 2 : ",20,195)
GuiCtrlSetColor ( $label_copy2 , 0x1eff00 ) ;vert
EndIf
Else
MsgBox(54,"Erreur","Effectuer une synchronisation avant.")
EndIf
EndFunc
; - - - - - - - - - - Dernier fichier Backup
Func last_file_back()
$dateplusrecent = 0
$fichierplusrecent = ""
FileChangeDir("c:\saveqle")
$search = FileFindFirstFile("backup_*.*")
; Check if the search was successful
If $search = -1 Then
MsgBox(0, "Error", "No files/directories matched the search pattern")
Exit
EndIf
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
$datefichier = FileGetTime($file,0,1)
if $datefichier > $dateplusrecent then
$dateplusrecent = $datefichier
Global $fichierplusrecent1 = $file
EndIf
WEnd
; MsgBox(1,"Fichier plus récent",$fichierplusrecent & @CR & $dateplusrecent)
$label_fichier1 = GUICtrlCreateLabel("Fichier 1 : " & $fichierplusrecent1,20,60)
; Close the search handle
FileClose($search)
EndFunc
; - - - - - - - - - - Dernier fichier Script
Func last_file_script()
$dateplusrecent = 0
$fichierplusrecent = ""
FileChangeDir("c:\saveqle")
$search = FileFindFirstFile("script*.*")
; Check if the search was successful
If $search = -1 Then
MsgBox(0, "Error", "No files/directories matched the search pattern")
Exit
EndIf
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
$datefichier = FileGetTime($file,0,1)
if $datefichier > $dateplusrecent then
$dateplusrecent = $datefichier
Global $fichierplusrecent2 = $file
EndIf
WEnd
; MsgBox(1,"Fichier plus récent",$fichierplusrecent & @CR & $dateplusrecent)
$label_fichier2 = GUICtrlCreateLabel("Fichier 2 : " & $fichierplusrecent2,20,80)
; Close the search handle
FileClose($search)
EndFunc