Ulysse31 Posted January 29, 2015 Share Posted January 29, 2015 (edited) Hi, I wanted to set up an auto data backup during the night (2 am). With some browsing around and with the help file I did this : expandcollapse popup#include <Date.au3> #include <MsgBoxConstants.au3> $time = @HOUR Local $iTimeout = 10 Local $iFreeSpace = DriveSpaceFree("F:\") MsgBox($MB_SYSTEMMODAL, "Information", "Espace nécessaire: 130 000 MB" & @LF & "Espace libre: " & $iFreeSpace & " MB", $itimeout) While 1 If $time = "02" Then If FileExists("F:\") Then sleep(100) Local $iFreeSpace = DriveSpaceFree("F:\") ; Find the free disk space of the home drive, generally this is the C:\ drive. ;MsgBox($MB_SYSTEMMODAL, "Information", "Espace nécessaire: 130 000 MB" & @LF & "Espace libre: " & $iFreeSpace & " MB") If $iFreeSpace <= 130000 Then MsgBox($MB_SYSTEMMODAL, "Erreur", "L'espace disponible est insuffisant, veuillez insérer un autre disque et relancer le programme.") Exit EndIf Else MsgBox($MB_SYSTEMMODAL, 'Erreur', "Veuillez insérer le disque de Sauvegarde puis relancez le programme.") Exit EndIf Local $iTimeout = 10 MsgBox($MB_SYSTEMMODAL, 'Sauvegarde', "L'opération de Sauvegarde va débuter", $itimeout) DirCopy("D:\Serveur\ARCHI GH-Serv\Dropbox\", "G:\Sauvegarde\", $FC_OVERWRITE + $FC_CREATEPATH) sleep(72000000) Else If FileExists("F:\") Then sleep(100) Local $iFreeSpace = DriveSpaceFree("F:\") ; Find the free disk space of the home drive, generally this is the C:\ drive. ;MsgBox($MB_SYSTEMMODAL, "Information", "Espace nécessaire: 130 000 MB" & @LF & "Espace libre: " & $iFreeSpace & " MB") If $iFreeSpace <= 130000 Then MsgBox($MB_SYSTEMMODAL, "Erreur", "L'espace disponible est insuffisant, veuillez insérer un autre disque (F:\) et relancer le programme.") Exit EndIf Else MsgBox($MB_SYSTEMMODAL, 'Erreur', "Veuillez insérer le disque de Sauvegarde puis relancez le programme.") Exit EndIf Sleep(3500000) EndIf WEnd Previously to that I made by myself few scripts which had undetected errors (to my eyes), resulting among other things in overflows. Since i am pretty new to this I want to know if my script is risk-free. Thanks ! Edited January 29, 2015 by Ulysse31 Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted January 29, 2015 Share Posted January 29, 2015 I use Autoit for a ton of things but for a simple backup I think I would just use a .bat file with robocopy or xcopy and then schedule it as a task. My normal backup script is robocopy with /e /mir /np flags. Link to comment Share on other sites More sharing options...
Solution czardas Posted January 29, 2015 Solution Share Posted January 29, 2015 (edited) It looks good to me, well done! I ran Tidy and removed some duplicate variable declarations. These declarations would not have caused any real problems, but it's better. The recursion errors you encountered previously will not occur. I didn't see anything else wrong. Now you have to test it. ; expandcollapse popup#include <Date.au3> #include <MsgBoxConstants.au3> ; ========> Only need to declare the following three variables once. <======== Local $time = @HOUR Local $iTimeout = 10 Local $iFreeSpace = DriveSpaceFree("F:\") MsgBox($MB_SYSTEMMODAL, "Information", "Espace nécessaire: 130 000 MB" & @LF & "Espace libre: " & $iFreeSpace & " MB", $iTimeout) While 1 If $time = "02" Then If FileExists("F:\") Then Sleep(100) $iFreeSpace = DriveSpaceFree("F:\") ; Find the free disk space of the home drive, generally this is the C:\ drive. ;MsgBox($MB_SYSTEMMODAL, "Information", "Espace nécessaire: 130 000 MB" & @LF & "Espace libre: " & $iFreeSpace & " MB") If $iFreeSpace <= 130000 Then MsgBox($MB_SYSTEMMODAL, "Erreur", "L'espace disponible est insuffisant, veuillez insérer un autre disque et relancer le programme.") Exit EndIf Else MsgBox($MB_SYSTEMMODAL, 'Erreur', "Veuillez insérer le disque de Sauvegarde puis relancez le programme.") Exit EndIf $iTimeout = 10 MsgBox($MB_SYSTEMMODAL, 'Sauvegarde', "L'opération de Sauvegarde va débuter", $iTimeout) DirCopy("D:\Serveur\ARCHI GH-Serv\Dropbox\", "G:\Sauvegarde\", $FC_OVERWRITE + $FC_CREATEPATH) Sleep(72000000) Else If FileExists("F:\") Then Sleep(100) $iFreeSpace = DriveSpaceFree("F:\") ; Find the free disk space of the home drive, generally this is the C:\ drive. ;MsgBox($MB_SYSTEMMODAL, "Information", "Espace nécessaire: 130 000 MB" & @LF & "Espace libre: " & $iFreeSpace & " MB") If $iFreeSpace <= 130000 Then MsgBox($MB_SYSTEMMODAL, "Erreur", "L'espace disponible est insuffisant, veuillez insérer un autre disque (F:\) et relancer le programme.") Exit EndIf Else MsgBox($MB_SYSTEMMODAL, 'Erreur', "Veuillez insérer le disque de Sauvegarde puis relancez le programme.") Exit EndIf Sleep(3500000) EndIf WEnd ; Edit Actually I do see one more thing. Perhaps you need to add error handling after the 5th line. Something like: Local $iFreeSpace = DriveSpaceFree("F:\") If @Error Then MsgBox($MB_SYSTEMMODAL, "Information", "Drive F not found") Exit EndIf Edited January 29, 2015 by czardas Ulysse31 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Ulysse31 Posted January 29, 2015 Author Share Posted January 29, 2015 Thanks, I sure feel a lot better letting it run in the background with your confirmation. I'm glad I could achieve such result by myself Great community ! czardas 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now