lansti Posted September 21, 2009 Share Posted September 21, 2009 (edited) 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? expandcollapse popup$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 September 22, 2009 by lansti Link to comment Share on other sites More sharing options...
99ojo Posted September 22, 2009 Share Posted September 22, 2009 (edited) 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? expandcollapse popup$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 September 22, 2009 by 99ojo Link to comment Share on other sites More sharing options...
lansti Posted September 22, 2009 Author Share Posted September 22, 2009 Ah, lovely. But there are some error messages, but i will try to fix these myself. Thank you very much. Best Lansti Link to comment Share on other sites More sharing options...
99ojo Posted September 22, 2009 Share Posted September 22, 2009 (edited) 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 Stefan Edited September 22, 2009 by 99ojo Link to comment Share on other sites More sharing options...
lansti Posted September 22, 2009 Author Share Posted September 22, 2009 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 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. Link to comment Share on other sites More sharing options...
99ojo Posted September 22, 2009 Share Posted September 22, 2009 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. 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 Link to comment Share on other sites More sharing options...
lansti Posted September 22, 2009 Author Share Posted September 22, 2009 Hi,have a look for return values, e.g. DirMove :Return ValueSuccess: Returns 1. Failure: Returns 0 if there is an error moving the directory. ;-))StefanIf I use 1, i do not get any error messages, but if i use 0 i got 3 error messages... Link to comment Share on other sites More sharing options...
99ojo Posted September 22, 2009 Share Posted September 22, 2009 (edited) 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 September 22, 2009 by 99ojo 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