Jump to content

Help with automated backup script


Recommended Posts

Hi there,

I am a new poster and I have a question that I need a little help with. I apologize if I am asking something that might have been covered before.

Here is what I am doing...

I wrote two batch files for myself that does the following...

First batch file ran on Odd Months (Jan, Mar, May, Jul, Sep, Nov) and performs the following function.

XCOPY X:\ Y:\

RMDIR Z:\

Second batch file ran on Even Months (Feb, Apr, Jun, Aug, Oct, Dec) and performs the following function.

XCOPY X:\ Z:\

RMDIR Y:\

These basically make a monthly backup of a drive that holds all my MP3's among other files of mine.

A little background history

I was having a problem learning how to right the IF... THEN... ELSE.. Statement for in the batch file and I stumbled upon your program here. As I read some of the stuff I got the idea of that I could write a little (2 lines) script with this program and then let windows Task Scheduler handle my IF... THEN... ELSE... issue.

No I want to go a step further.

Currently I have two AutoIt scripts that I made into EXE files. One is designed to the Odd Month BATCH file and the other is designed to run the Even Month BATCH file.

I wan tot know if there is a way to check just the date. Then I want to know if there is a way that I can make just one EXE that will open when scheduled and do the following... (Warning I have this written in laymens terms)

IF month = Jan, Mar, May, Jul, Sep, Nov

THEN Run OMBUS.BATCH

END IF

IF month = Feb, Apr, Jun, Aug, Oct, Dec

THEN Run EMBUS.BATCH

END IF

Any help that you guys can give me would be greatly appreciated. I know that I could probably run this whole thing in Autoit but as of right now I am happy with using DOS to perform the actual backup.

I do have other things that I eventually want to do but I will tackle them after I get the basics of this thing running.

Again thank you for any help that anyone can give me here. It will be greatly appreciated!

[font="Arial"]James D. Williams[/font]

Link to comment
Share on other sites

This'll handle your If Then statement..

#include <Date.au3>

$OddMonths = "Jan, Mar, May, Jul, Sep, Nov"
$EvenMonths = "Feb, Apr, Jun, Aug, Oct, Dec"

; Retrieve the long name
If StringInStr ($OddMonths, _DateToMonth(@MON, 1)) Then
    MsgBox (0, "Odd Month", _DateToMonth(@MON, 1))
    ;Other commands for Odd Months here
ElseIf StringInStr ($EvenMonths, _DateToMonth(@MON, 1)) Then
    MsgBox (0, "Even Month", _DateToMonth(@MON, 1))
    ;Other commands for Even Months here
Else
    MsgBox (0, "Problem", "One of the abbreviations must not have been right.")
EndIf

As for the rest of what you want to do, you should be able to do it all within AutoIt pretty easily, check the manual for DirCopy and DirRemove.

Edited by exodius
Link to comment
Share on other sites

Hey exodius,

Thanx for the reply. I do have one question though... ok actually two and I am sorry because I am a nubie to some of this...

First do I have to have that Date.au3 file in the same place as my script and along with that if I make this an EXE do I need to do anything else as far as "merging" scripts?

Second thing is, where do I put the command to run my batch file? Would it replace this line with the appropriate file to run?

MsgBox (0, "Odd Month", _DateToMonth(@MON, 1))

Again thanx for the help and patients with a newbie here.

[font="Arial"]James D. Williams[/font]

Link to comment
Share on other sites

Hey exodius,

Thanx for the reply. I do have one question though... ok actually two and I am sorry because I am a nubie to some of this...

First do I have to have that Date.au3 file in the same place as my script and along with that if I make this an EXE do I need to do anything else as far as "merging" scripts?

Second thing is, where do I put the command to run my batch file? Would it replace this line with the appropriate file to run?

MsgBox (0, "Odd Month", _DateToMonth(@MON, 1))

Again thanx for the help and patients with a newbie here.

Not bad questions at all, when you use the command #include <Date.au3>, it basically includes the script "C:\Program Files\AutoIt\Include\Date.au3" in your script automatically and also inserts it into your compiled script automatically.

When you do #include <> it pulls from that default AutoIt directory, if you did #include "Date.au3" it would pull from the same directory your script was in, but just like above, it'll include it in both your script and any compiled exes...

And yes, you can replace those messageboxes with your run commands (or the AutoIt equivalents, I'd really encourage you to consider looking at them because what you want to do is pretty simple with those two commands...)

Link to comment
Share on other sites

I tried replacing it before I head back form you... I figured I had it saved and as long as I saved it to another file after I made my change, what could it hurt LOL.

I notice that the scripts are written what looks to be similar to say ASP. I have messed around with that a little so I am somewhat learning but I get confused.

So I was thinking that I might take this a small step further and say the heck with the windows Task Scheduler and maybe just write the schedule into the script itself.

I copied and pasted what I was thinking I should make it do. But I have no clue how to write the stuff in the logic of the language I only know how to put it in English. I have tabbed everything in so all my comments will have an * aside of them and start from the left margin. (I know that was probably all DUH)

#include <Date.au3>

*I set a point in the script and called it DAY. This where the IF THEN ELSE to check what day number it is of the month. (E.G. 1, 2, 3, etc.) I want this to be set to DAY = 1 so that the script initiates on the first day of the month.

:DAY

If (day = 1) Then

GoTo Time

Else GoTo Dayloop

*I set a point in the script and called it TIME this is where the IF THEN ELSE to check the time is set. I want this to read that if the TIME is egual to or greater than 02:00 **I goofed here and should have made this what it is... I originally had If (Time = < 02:00:00) Then

:TIME

If (Time = > 02:00:00) Then

GoTo Month

Else GoTo Timeloop

*I set a point in the script and called is MONTH. This is the IF THEN ELSE statement is to check which month it is. This also governs over which BATCH file to run depending on the month. This part was already written by exodius and seams to be working just fine for me!

:MONTH

$OddMonths = "Jan, Mar, May, Jul, Sep, Nov"

$EvenMonths = "Feb, Apr, Jun, Aug, Oct, Dec"

; Retrieve the long name

If StringInStr ($OddMonths, _DateToMonth(@MON, 1)) Then

Goto OMBCBUS

;Other commands for Odd Months here

ElseIf StringInStr ($EvenMonths, _DateToMonth(@MON, 1)) Then

GoTo EMBCBUS

;Other commands for Even Months here

Else GoTo DAY

EndIf

*This is my point in the script where the DAY IF THEN ELSE question fails. When it comes here the script is told to wait one day then go and run the DAY IF THEN ELSE question again.

:DAYLOOP

Wait Day+1

GoTo DAY

*This is my point in the script where the TIME IF THEN ELSE question fails. When it comes here the script is told to wait 5 minutes then go and run the TIME IF THEN ELSE question again.

:TIMELOOP

Wait Time+00:05:00

GoTo TIME

*These are the places where the command to run the BATCH file is located. Basically if the script gets threw all my checks then it is to INITIATE one of these BATCH files depending on if it is an Even or Odd month. After it INITs the BATCH file I want it to go to the FWAIT area.

:OMBCBUS

Run (C:\_BCSBUS\BCBUS_OM.BAT)

GoTo FWAIT

:EMBCBUS

Run (C:\_BCSBUS\BCBUS_OM.BAT)

GoTo FWAIT

*Here is where the Final Wait step is. This designates that the script sits and waits for 27 days before it returns to the top of the file and reruns the script.

:FWAIT

Wait Day+27

GoTo DAY

;EOF

So does anyone think that this can be done I am sure it can be I just dont know how to. I would like to learn how to do this for myself but I only learn by example and unfortunately I dont see any examples like this in the programs demo files. In the mean time I am going to try and troll around the msg brds and see if I can find something that will give me an idea of what the heck to type to put this into an actual program language. I would also like if someone has ideas could you not only supply me with the script but explain some of the parts so that I can start to learn what I am looking at. This way I can also learn how to manipulate what I have

Thank you for any and all help anyone can give me.

Edited by rsmedude

[font="Arial"]James D. Williams[/font]

Link to comment
Share on other sites

Ok I am feeling either really dumb... or I just dont know how to use the search all that well.

I cant even seam to get started on my own cause I cant figure out what the syntax would be for requesting the day and time and such like that.

Any help would be greatly appreciated. I will also gladly make all my batch files available for anyone who would be interested in using them... either for there use or to rehash into a single autoit type file... that is something that I am ultimately looking at but I want to start slow and learn here a little.

[font="Arial"]James D. Williams[/font]

Link to comment
Share on other sites

Ok so I think I found my answer in this thread that I stumbled apon:

Alarm Clock, little program i created for a person at my work

Here is what they are doing:

@Hour @Min @Sec

If @Hour = "6" And @Min = "30" Then _Alarm();This alarm will go off @ 6:30 AM

Here are my modications to do what I need: (I Hope)

@Hour @Min @Sec

IF @Hour =< "2" And @Min =< "00" THEN

GOTO(MONTH)

ELSE Loop(TIME)

The only thing I am not sure on is will this do what I want. I know it will check against the system time but will it go to the designated spots in the script?

If someoen could double chekc me I would greatly appriciate it. I am going to try and give it a whirl when I get home.

Thanx for any help here I would greatly appricaite it.

[font="Arial"]James D. Williams[/font]

Link to comment
Share on other sites

Ok so I think I found my answer in this thread that I stumbled apon:

Alarm Clock, little program i created for a person at my work

Here is what they are doing:

@Hour @Min @Sec

If @Hour = "6" And @Min = "30" Then _Alarm();This alarm will go off @ 6:30 AM

Here are my modications to do what I need: (I Hope)

@Hour @Min @Sec

IF @Hour =< "2" And @Min =< "00" THEN

GOTO(MONTH)

ELSE Loop(TIME)

The only thing I am not sure on is will this do what I want. I know it will check against the system time but will it go to the designated spots in the script?

If someoen could double chekc me I would greatly appriciate it. I am going to try and give it a whirl when I get home.

Thanx for any help here I would greatly appricaite it.

This gets what you posted above closer to the AutoIt Syntax for what you want to do...

#include <Date.au3>
 Opt ("TrayIconDebug", 1)

While 1
    If (@Mday = 01) Then
        _TimeCheck ()
    Else
        _SleepForADay()
    EndIf
WEnd

Func _TimeCheck()
    If (@HOUR >= 02) Then
        _MonthCheck()
    Else
        _Timeloop()
    EndIf
EndFunc

Func _MonthCheck()
    $OddMonths = "Jan, Mar, May, Jul, Sep, Nov"
    $EvenMonths = "Feb, Apr, Jun, Aug, Oct, Dec"

    ; Retrieve the long name
    If StringInStr ($OddMonths, _DateToMonth(@MON, 1)) Then
        Run ("C:\_BCSBUS\BCBUS_OM.BAT")
        
    ElseIf StringInStr ($EvenMonths, _DateToMonth(@MON, 1)) Then
        Run ("C:\_BCSBUS\BCBUS_OM.BAT")
    EndIf
        
    For $x = 27 To 0 Step -1
        ToolTip("Sleeping for " & $x & " more days...", 0, 0)
        Sleep (86400000)
    Next
EndFunc

Func _SleepForADay()
 Sleep (86400000);1000 ms in a second * 60 seconds in a minute * 60 Minutes in an hour * 24 hours
EndFunc

Func _Timeloop()
    Sleep (300000); 1000 ms in a second * 60 seconds in a minute * 5 minutes
EndFunc
Link to comment
Share on other sites

This gets what you posted above closer to the AutoIt Syntax for what you want to do...

#include <Date.au3>
 Opt ("TrayIconDebug", 1)

While 1
    If (@Mday = 01) Then
        _TimeCheck ()
    Else
        _SleepForADay()
    EndIf
WEnd

Func _TimeCheck()
    If (@HOUR >= 02) Then
        _MonthCheck()
    Else
        _Timeloop()
    EndIf
EndFunc

Func _MonthCheck()
    $OddMonths = "Jan, Mar, May, Jul, Sep, Nov"
    $EvenMonths = "Feb, Apr, Jun, Aug, Oct, Dec"

    ; Retrieve the long name
    If StringInStr ($OddMonths, _DateToMonth(@MON, 1)) Then
        Run ("C:\_BCSBUS\BCBUS_OM.BAT")
        
    ElseIf StringInStr ($EvenMonths, _DateToMonth(@MON, 1)) Then
        Run ("C:\_BCSBUS\BCBUS_OM.BAT")
    EndIf
        
    For $x = 27 To 0 Step -1
        ToolTip("Sleeping for " & $x & " more days...", 0, 0)
        Sleep (86400000)
    Next
EndFunc

Func _SleepForADay()
 Sleep (86400000);1000 ms in a second * 60 seconds in a minute * 60 Minutes in an hour * 24 hours
EndFunc

Func _Timeloop()
    Sleep (300000); 1000 ms in a second * 60 seconds in a minute * 5 minutes
EndFuncoÝ÷ Ûú®¢×kçmç(v)à¶ZÊ«¢rF§t¦ëmxê뢶­.)ÞßÒâíýJW§Î¸ÓM4Ñ«­¢+ÙÕ¹}M±Á½Éä ¤(M±À àØÐÀÀÀÀÀ¤(ìÄÀÀÀµÌ¥¸Í½¹¨ØÀͽ¹Ì¥¸µ¥¹ÕѨØÀ5¥¹ÕÑÌ¥¸¸¡½ÕȨÈС½ÕÉÌ)¹Õ¹

I attached an image of what is giving me.

So my question is what the heck is going on here LOL?

Also I would like to learn what I am reading in this coding... Is there somewhere that I am missing that I can go to so I can learn the commands and there variants in the syntax? I am trying to learn so that I don't have to run back o you guys (No Offence) every time I want to do or try something new.

Thank you for the help here.

[font="Arial"]James D. Williams[/font]

Link to comment
Share on other sites

I attached an image of what is giving me.

So my question is what the heck is going on here LOL?

Also I would like to learn what I am reading in this coding... Is there somewhere that I am missing that I can go to so I can learn the commands and there variants in the syntax? I am trying to learn so that I don't have to run back o you guys (No Offence) every time I want to do or try something new.

Thank you for the help here.

You can learn more about using AutoIt by going to this post and downloading/running AutoIt 1-2-3. You can also learn about each of the commands/syntax used by looking them up in helpfile.

What you were experiencing with that command was not an error, the trayicon displayed that because that's the current line that it was on. The script did all of the checks and was "sleeping" (pausing) for that many MS, which I explained the logic as being 1000 ms in a second * 60 seconds in a minute * 60 Minutes in an hour * 24 hours = 86400000. Incidentally that's a very long time for a script to pause.

But if that explanation's a little hard to wrap your mind around, try replacing the _SleepForADay() function with this one to sleep for one day:

Func _SleepForADay()
    For $Days = 0 to 0 Step -1
        For $Hours = 23 to 0 Step -1
            For $Minutes = 59 to 0 Step -1
                For $Seconds = 59 to 0 Step -1
                    Sleep (1000)
                    ToolTip ("Sleeping for " & $Days & " days, " & $Hours & " hours, " & $Minutes & " minutes, " & $Seconds & " seconds.", 0, 0)
                Next
            Next
        Next
    Next
EndFunc
Edited by exodius
Link to comment
Share on other sites

You can learn more about using AutoIt by going to this post and downloading/running AutoIt 1-2-3. You can also learn about each of the commands/syntax used by looking them up in helpfile.

What you were experiencing with that command was not an error, the trayicon displayed that because that's the current line that it was on. The script did all of the checks and was "sleeping" (pausing) for that many MS, which I explained the logic as being 1000 ms in a second * 60 seconds in a minute * 60 Minutes in an hour * 24 hours = 86400000. Incidentally that's a very long time for a script to pause.

But if that explanation's a little hard to wrap your mind around, try replacing the _SleepForADay() function with this one to sleep for one day:

Func _SleepForADay()
    For $Days = 0 to 0 Step -1
        For $Hours = 23 to 0 Step -1
            For $Minutes = 59 to 0 Step -1
                For $Seconds = 59 to 0 Step -1
                    Sleep (1000)
                    ToolTip ("Sleeping for " & $Days & " days, " & $Hours & " hours, " & $Minutes & " minutes, " & $Seconds & " seconds.", 0, 0)
                Next
            Next
        Next
    Next
EndFunc

I get what youre saying now. I was looking at it as that the there was an error cause it paused and was showing me a red "X". So it wasnt that it errored out rather that it was just doing what it was suppose to and that it wait till specified event, in this case a certain time, to then proceed.

I can write this stuff in English I just have a hard time writing it in the "programming language" go figure LOL.

I will look at this again probably Wednesday since I have to go to my part time job tomorrow in the morning. In the mean time I will look at the help files and stuff that you pointed me to and mess around a little in there and see if I can get my dumb butt a little clue.

Thank you for the help I really do appreciate it and I do apologize for the seemingly dumb questions that I have.

[font="Arial"]James D. Williams[/font]

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...