Jump to content

Auto BackUp script


 Share

Go to solution Solved by czardas,

Recommended Posts

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 :

#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 by Ulysse31
Link to comment
Share on other sites

  • Solution

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.

;

#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 by czardas
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...