Sign in to follow this  
Followers 0
Ulysse31

Auto BackUp script

4 posts in this topic

#1 ·  Posted (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 :

#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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

#3 ·  Posted (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.

;

#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
1 person likes this

Share this post


Link to post
Share on other sites

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  :thumbsup:

Great community !

1 person likes this

Share this post


Link to post
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
Sign in to follow this  
Followers 0