Jump to content
Sign in to follow this  
lansti

Help with backup and keep 5 backups

Recommended Posts

lansti

I have created a little program that should be used on a standalone client(not on network), where the user should manage backups to disk.

I have been working with different solutions for how to keep the last 5 backups, and i'm not a good programmer.

So what i want is that user can manage backups to disk, but everytime the user take a backup, it copy by date.... And automatic delete the oldest backup when I reash 5 backups.

Is there anyone who can help me out with the last lines in my script?

$versjon = "0.1"
;======================================================

#Include <Constants.au3>
#Include<file.au3>
#NoTrayIcon
#Include <Date.au3>

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Local $hBmp
;$i=0


;======================================================
$MsgTitle = "Road Backup - TV 2 AS"
$s_FileError = ""
$sourcefolder = "c:\road"    
;======================================================

TraySetIcon("road.ICO")
TraySetToolTip("Road Backup " & $versjon)

Opt("TrayMenuMode",1)   
$BackupItem = TrayCreateItem("Backup av Road...")
TrayCreateItem("")
$OmItem = TrayCreateItem("Om")
$AvsluttItem = TrayCreateItem("Avslutt")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
    Case $msg = 0
            ContinueLoop
        ;=====================================================================
        ;     Backup av Road
        ;=====================================================================
        Case $msg = $BackupItem
            $outputdrive = InputBox($MsgTitle, "Backup av Road data. Write in the path where you want to put your backup:" & @LF & @LF, "e:\", "",600,170)
            
            if FileExists($outputdrive & "road") Then
                if FileExists($outputdrive & "road\lastbackup") Then
                    DirRemove($outputdrive & "road\lastbackup", 1) Then
                EndIf
                
                DirMove($outputdrive & "road", $outputdrive & "lastbackup")

                
;               if $i=3 Then
;                   $y=0
;                   $x=2
;                   while $y <= 2
;                       DirCopy($outputdrive & "Tidligere backup_" & $x, $outputdrive & "Tidligere backup_" & $y)
;                       
;                       
;                       
;                       DirRemove($outputdrive & "Tidligere backup_" & $y, 1)
;                       ;DirCopy($outputdrive & "Tidligere backup_" & $x, $outputdrive & "Tidligere backup_" & $y)
;                       $x = $x + 1     
;                       $y = $y + 1                     
;                   WEnd
;
;                   $i = 0
;               EndIf
            
            EndIf
            
            DirCreate ($outputdrive)
            _FileCopy($sourcefolder,$outputdrive)
            
            if @error Then
                MsgBox(48,$MsgTitle,"Backup was unsuccessful")
            Else
                MsgBox(64,$MsgTitle,"Backup was successful",5)
            EndIf
            
        Case $msg = $OmItem
            Msgbox(64, $MsgTitle, "Backup for Road - Standalone Klient"& @LF &"NameLF &"2009"& @LF & "-------------------------" & @LF & "Programversjon: " & $versjon & @LF & "-------------------------")
        Case $msg = $AvsluttItem
            ExitLoop
    EndSelect
WEnd

Exit

Func _FileCopy($sourcefolder,$outputdrive) 
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($outputdrive).CopyHere($sourcefolder,$FOF_RESPOND_YES)
EndFunc

Best regards

lansti

Edited by lansti

Share this post


Link to post
Share on other sites
99ojo

I have created a little program that should be used on a standalone client(not on network), where the user should manage backups to disk.

I have been working with different solutions for how to keep the last 5 backups, and i'm not a good programmer.

So what i want is that user can manage backups to disk, but everytime the user take a backup, it copy by date.... And automatic delete the oldest backup when I reash 5 backups.

Is there anyone who can help me out with the last lines in my script?

$versjon = "0.1"
;======================================================

#Include <Constants.au3>
#Include<file.au3>
#NoTrayIcon
#Include <Date.au3>

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Local $hBmp
;$i=0


;======================================================
$MsgTitle = "Road Backup - TV 2 AS"
$s_FileError = ""
$sourcefolder = "c:\road"    
;======================================================

TraySetIcon("road.ICO")
TraySetToolTip("Road Backup " & $versjon)

Opt("TrayMenuMode",1)   
$BackupItem = TrayCreateItem("Backup av Road...")
TrayCreateItem("")
$OmItem = TrayCreateItem("Om")
$AvsluttItem = TrayCreateItem("Avslutt")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
    Case $msg = 0
            ContinueLoop
        ;=====================================================================
        ;     Backup av Road
        ;=====================================================================
        Case $msg = $BackupItem
            $outputdrive = InputBox($MsgTitle, "Backup av Road data. Write in the path where you want to put your backup:" & @LF & @LF, "e:\", "",600,170)
            
            if FileExists($outputdrive & "road") Then
                if FileExists($outputdrive & "road\lastbackup") Then
                    DirRemove($outputdrive & "road\lastbackup", 1) Then
                EndIf
                
                DirMove($outputdrive & "road", $outputdrive & "lastbackup")

                
;               if $i=3 Then
;                   $y=0
;                   $x=2
;                   while $y <= 2
;                       DirCopy($outputdrive & "Tidligere backup_" & $x, $outputdrive & "Tidligere backup_" & $y)
;                       
;                       
;                       
;                       DirRemove($outputdrive & "Tidligere backup_" & $y, 1)
;                       ;DirCopy($outputdrive & "Tidligere backup_" & $x, $outputdrive & "Tidligere backup_" & $y)
;                       $x = $x + 1     
;                       $y = $y + 1                     
;                   WEnd
;
;                   $i = 0
;               EndIf
            
            EndIf
            
            DirCreate ($outputdrive)
            _FileCopy($sourcefolder,$outputdrive)
            
            if @error Then
                MsgBox(48,$MsgTitle,"Backup was unsuccessful")
            Else
                MsgBox(64,$MsgTitle,"Backup was successful",5)
            EndIf
            
        Case $msg = $OmItem
            Msgbox(64, $MsgTitle, "Backup for Road - Standalone Klient"& @LF &"NameLF &"2009"& @LF & "-------------------------" & @LF & "Programversjon: " & $versjon & @LF & "-------------------------")
        Case $msg = $AvsluttItem
            ExitLoop
    EndSelect
WEnd

Exit

Func _FileCopy($sourcefolder,$outputdrive) 
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($outputdrive).CopyHere($sourcefolder,$FOF_RESPOND_YES)
EndFunc

Best regards

lansti

Hi,

something like this:

Directory structure on backup drive, should be already created:

\road -> actual

\lastbackup -> backup before actual

\Tidligere backup_1

\Tidligere backup_2

\Tidligere backup_3

\Tidligere backup_4

Global $sourcefolder = "c:\road"

Func _backup ()
    $outputdrive = InputBox($MsgTitle, "Backup av Road data. Write in the path where you want to put your backup:" & @LF & @LF, "e:\", "",600,170)
    ;here may some checking for directory structure mentioned above
    For $i = 3 To 1 Step - 1
        $error = DirRemove ($outputdrive & "Tidligere backup_" & $i + 1, 1)
        If $error = 0 Then MsgBox (0,"Error", "Error removing directory " & $outputdrive & "Tidligere backup_" & $i + 1)
        DirMove ($outputdrive & "Tidligere backup_" & $i, $outputdrive & "Tidligere backup_" & $i + 1)
    Next
    DirMove ($outputdrive & "lastbackup", $outputdrive & "Tidligere backup_1")
    DirMove ($outputdrive & "road", $outputdrive & "lastbackup")
    DirCopy ($sourcefolder, $outputdrive & "road")
EndFunc

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites
lansti

Ah, lovely.

But there are some error messages, but i will try to fix these myself.

Thank you very much.

Best

Lansti

Share this post


Link to post
Share on other sites
99ojo

Ah, lovely.

But there are some error messages, but i will try to fix these myself.

Thank you very much.

Best

Lansti

Hi,

Ooooohhhhh, i make a big logical mistake in my function:

Global $sourcefolder = "c:\road"

Func _backup ()
    $outputdrive = InputBox($MsgTitle, "Backup av Road data. Write in the path where you want to put your backup:" & @LF & @LF, "e:\", "",600,170)
    ;here may some checking for directory structure mentioned above
    $error = DirRemove ($outputdrive & "Tidligere backup_4", 1)
    If $error = 0 Then 
        MsgBox (0,"Error", "Error removing directory " & $outputdrive & "Tidligere backup_" & $i + 1)
        ;Exit
    EndIf
    For $i = 3 To 1 Step - 1
        $error = DirMove ($outputdrive & "Tidligere backup_" & $i, $outputdrive & "Tidligere backup_" & $i + 1)
        If $error = 0 Then 
            MsgBox (0,"Error", "Error moving directory " & $outputdrive & "Tidligere backup_" & $i + 1)
            ;Exit
        EndIf
    Next
    DirMove ($outputdrive & "lastbackup", $outputdrive & "Tidligere backup_1")
    DirMove ($outputdrive & "road", $outputdrive & "lastbackup")
    DirCopy ($sourcefolder, $outputdrive & "road")
EndFunc

:D

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites
lansti

Hi,

Ooooohhhhh, i make a big logical mistake in my function:

Global $sourcefolder = "c:\road"

Func _backup ()
    $outputdrive = InputBox($MsgTitle, "Backup av Road data. Write in the path where you want to put your backup:" & @LF & @LF, "e:\", "",600,170)
    ;here may some checking for directory structure mentioned above
    $error = DirRemove ($outputdrive & "Tidligere backup_4", 1)
    If $error = 0 Then 
        MsgBox (0,"Error", "Error removing directory " & $outputdrive & "Tidligere backup_" & $i + 1)
        ;Exit
    EndIf
    For $i = 3 To 1 Step - 1
        $error = DirMove ($outputdrive & "Tidligere backup_" & $i, $outputdrive & "Tidligere backup_" & $i + 1)
        If $error = 0 Then 
            MsgBox (0,"Error", "Error moving directory " & $outputdrive & "Tidligere backup_" & $i + 1)
            ;Exit
        EndIf
    Next
    DirMove ($outputdrive & "lastbackup", $outputdrive & "Tidligere backup_1")
    DirMove ($outputdrive & "road", $outputdrive & "lastbackup")
    DirCopy ($sourcefolder, $outputdrive & "road")
EndFunc

:D

Stefan

Thanks, and i also had to change:

If $error = 0 Then 
            MsgBox (0,"Error", "Error moving directory " & $outputdrive & "Tidligere backup_" & $i + 1)
            ;Exit
        EndIf

to...

If $error = 1 Then 
            MsgBox (0,"Error", "Error moving directory " & $outputdrive & "Tidligere backup_" & $i + 1)
            ;Exit
        EndIf

It works fine now, thank you mr. :D

Share this post


Link to post
Share on other sites
99ojo

Thanks, and i also had to change:

If $error = 0 Then 
            MsgBox (0,"Error", "Error moving directory " & $outputdrive & "Tidligere backup_" & $i + 1)
            ;Exit
        EndIf

to...

If $error = 1 Then 
            MsgBox (0,"Error", "Error moving directory " & $outputdrive & "Tidligere backup_" & $i + 1)
            ;Exit
        EndIf

It works fine now, thank you mr. :D

Hi,

have a look for return values, e.g. DirMove :

Return Value

Success: Returns 1.

Failure: Returns 0 if there is an error moving the directory.

;-))

Stefan

Share this post


Link to post
Share on other sites
lansti

Hi,

have a look for return values, e.g. DirMove :

Return Value

Success: Returns 1.

Failure: Returns 0 if there is an error moving the directory.

;-))

Stefan

If I use 1, i do not get any error messages, but if i use 0 i got 3 error messages...

Share this post


Link to post
Share on other sites
99ojo

Hi,

If you don't have the directory structure created, you should place a if FileExist before the DirRemove.

Change

$error = DirRemove ($outputdrive & "Tidligere backup_4", 1)
    If $error = 0 Then 
        MsgBox (0,"Error", "Error removing directory " & $outputdrive & "Tidligere backup_" & $i + 1)
        ;Exit
    EndIf

to

$error = DirRemove ($outputdrive & "Tidligere backup_4", 1)
    If $error = 0 Then 
        MsgBox (0,"Error", "Error removing directory " & $outputdrive & "Tidligere backup_4") ; if msgbox appears, check if directory exists

        ;Exit
    EndIf

You may post the error messages as well....

;-))

Stefan

Edited by 99ojo

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.