Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Backup Script-copy

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,41914
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Backup Script-copy
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2 3   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Backup Script-copy - 1/11/2007 4:59:06 AM   
  netman06

 

Posts: 105
Score: 0
Joined: 10/19/2006
Status: offline
Hello,

What I'm trying to do is create a file copy script, that will look inside a folder and find files named by the days of the week, RE: Monday, tuesday, etc, and copy the backup files with the same name into the days of the week folders.

then age the files inside this folders, by 7 days, so I will have a weeks worth of backup files inside these folders.

I found information on this forums regarding robocopy, but did not find any thing by searching the forums regarding ingrating robocopy with vbs to do this.

here is with code I'm working with: just a start, with same basic idea, but with files only.


      
 
 
Post #: 1
 
 RE: Backup Script-copy - 1/11/2007 5:01:08 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
So to help you I think we will need some more information. What exactly is the form of the name of the files in the source folder? What does the name need to look like in the individual day folders?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 2
 
 RE: Backup Script-copy - 1/11/2007 5:11:52 AM   
  netman06

 

Posts: 105
Score: 0
Joined: 10/19/2006
Status: offline
HI, ebgreen

I remember you where the one, that recommend robocopy, what a great utility. I read documentation on it, and it seemed like to do not have the ability to copy file to folders based on name like (tuesday).






The files that I'm working with are the days of the week.

Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday

File type is a bkf, ntbackup file.

backup folder name is: Den_Server_Backup

By default I have all files go into a folder, I would like to then have a script run after the backup and put any file with say Tuesday into the Tuesday folder, then also age the file, because of space limits, say only keep 7 days worth of these files, then delete them.

Hope that helps,

Thanks,

Mike

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Backup Script-copy - 1/11/2007 5:17:26 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
So you have a folder named Den_Server_Backup. In this folder would be 7 files:

Monday.bkf
Tuesday.bkf
Wednesday.bkf
Thursday.bkf
Friday.bkf
Saturday.bkf
Sunday.bkf

you want these files to be seperated into seven folders named for the days of the week.

Where will the day folders be? Subfolders of Den_Server_Backup? What do you want the name of the files to be in the day folders? Obviously they can't have the same name as they have in Den_Server_Backup or they would just overwrite the existing file each time that you copied one in.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 4
 
 RE: Backup Script-copy - 1/11/2007 5:41:35 AM   
  netman06

 

Posts: 105
Score: 0
Joined: 10/19/2006
Status: offline
yes, good point.

Well I would put all files into the Den_Server_Backup folder, then copy to days of the week folder.but your right how can I handle this without overwriting the same say tuesday file with say the second or third copy.

Is there a way to age files before copying, like if, then, else statement?

This is a problem, I'm trying to learn as much as I can regarding vbscripting, but this is over my head.

Basically all I need is something to help me save 7 days of ntbackup files, so incase I need to restore back 7 days I'll have it. the main problem is the ntbackup, will not name the files on date or any custom naming standard, like Tuesday010307, if that was the case it would make it a lot more easy. know if someone here knows a way to name these files using ntbackup, please let me know. I thought about finding a way to have the script rename them based on date, but I again do not know even where to start that project.

thanks for all of you input.


Mike

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Backup Script-copy - 1/11/2007 6:03:55 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Ok...I'll rough something out and put it up shortly.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 6
 
 RE: Backup Script-copy - 1/11/2007 6:09:18 AM   
  netman06

 

Posts: 105
Score: 0
Joined: 10/19/2006
Status: offline
Sounds good!

Thanks,

Mike

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Backup Script-copy - 1/11/2007 6:37:57 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Give this a whirl. It is untested and off the cuff so there will probably be kinks to get worked out but it should start you in the right direction:


      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 8
 
 RE: Backup Script-copy - 1/11/2007 8:12:44 AM   
  netman06

 

Posts: 105
Score: 0
Joined: 10/19/2006
Status: offline
WOW!

Thanks alot for doing all of that work, it works great, and thanks for putting the great comments into the script, as a beginner, I learned the hard way, regarding the trailing \ , it took me a long time to figure that one out and it still get me sometimes.

I do have one question. The script when it renames the files, which is awesome, it write them like this example.

SUNDAY20070111bkf

it is missing the . for file extention

So my guess is it has do to with this code:


      

Hi, EBGreen

I tried several different things to get the . period to append to the file name, with no luck.

Also I found that the files still remain in the main folder DenServerBackup, and I was write this code up and thought that I have the ntbackup overwriting the files, so I guess I will not need this. what do you thing?


      

Thanks for all of your help,

Mike

(in reply to ebgreen)
 
 
Post #: 9
 
 RE: Backup Script-copy - 1/11/2007 8:19:15 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Ok, the missing . was part of the kinks.  Change this:

oFile.Copy dicDays(UCase(oFSO.GetBaseName(oFile.Name))) & oFSO.GetBaseName(oFile.Name) & GetTimeStamp(oFile) & oFSO.GetExtensionName(oFile.Name)

To this:

oFile.Copy dicDays(UCase(oFSO.GetBaseName(oFile.Name))) & oFSO.GetBaseName(oFile.Name) & GetTimeStamp(oFile) & "." & oFSO.GetExtensionName(oFile.Name)

I will also point out that I did not put in any code to cleanup the day folders and remove files that are older than 7 days.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 10
 
 RE: Backup Script-copy - 1/11/2007 8:20:39 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
So you want to delete the file after you copy it?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 11
 
 RE: Backup Script-copy - 1/11/2007 9:12:04 AM   
  netman06

 

Posts: 105
Score: 0
Joined: 10/19/2006
Status: offline
Well I guess you can see what A newbee, I am. Thanks that fix it.

Yes, if I can have it delete any file that is older then 7 days out of the days of the week folders.

C:\DenServerBackup\Monday
C:\DenServerBackup\Tuesday
C:\DenServerBackup\Wednesday
C:\DenServerBackup\Thursday
C:\DenServerBackup\Friday
C:\DenServerBackup\Saturday
C:\DenServerBackup\Sunday

Here is what I have, but I need some help with it. I'm getting a error mesage:

Visual Basic Scripting Edition  Expected 'End'  


You created a construct, but did not properly terminate it. The following table lists the VBScript constructs that must end with an End statement.




Construct
Terminating Statement


Sub


End Sub



Function


End Function



If


End If



Class


End Class



With


End With



Select


End Select
To correct this error


  • Terminate a Sub procedure with an associated End Sub statement.

  • Terminate a Function procedure with an associated End Function statement.

  • Terminate an If statement with an associated End If statement.

  • Terminate a Class statement with an associated End Class statement.

  • Terminate a With statement with an associated End With statement.

  • Terminate a Select Statement with an associated End Select statement.

      
EBGreen, what do you think about this code, can we get it to work, or do you have a better solution?

I have been troubleshoot this for over an hour with no luck, I know you can will be able to see the problem rightway.

Thanks,

Mike

(in reply to ebgreen)
 
 
Post #: 12
 
 RE: Backup Script-copy - 1/11/2007 9:43:39 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Give this code a try. Make sure you change the path constants.


      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 13
 
 RE: Backup Script-copy - 1/11/2007 10:00:11 AM   
  netman06

 

Posts: 105
Score: 0
Joined: 10/19/2006
Status: offline
Hi, EBGreen

That worked, but I was thinking more, I will also need to get the code in the previous post working, so that my external backup hard drive, does not run out of space, so if you can help me figure out this code to delete file that we copied into the days of the week folders, that are older then 7 days.

I know i might not be using the if else or if elseif statements correctly. Also I have the Expected 'End'  error message.

I fix one error in the second script:

This:
File.Delete True

and changed it to:

oFile.Delete True

so you can update your script.

Thanks for all of you help, if you have time, look at my script and give me some ideas to either make it better or how I can go about rewriting it.

Thanks,

Mike

(in reply to ebgreen)
 
 
Post #: 14
 
 RE: Backup Script-copy - 1/11/2007 11:40:41 AM   
  dm_4ever


Posts: 2414
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
Below is what you had. Notice how structuring it with indentations makes it easier to read and therefore easier to see what you're missing. I think you were missing an "End If".  This is by no means the most efficient. You might be able to shrink this in the same manner EBGreen has helped you out with the other parts of your script.


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 15
 
 RE: Backup Script-copy - 1/11/2007 2:19:54 PM   
  netman06

 

Posts: 105
Score: 0
Joined: 10/19/2006
Status: offline
Hi, dm_4ever
 
thanks for the comment, I do have a question regarding the End If's.
 
Why do you need the two End If's?
 
Also what does the Next really do, since I do not have anymore code after it?
 

      

 
I check the MSDN web site and found the information above, but it did not really help me.
 
I would think it would have told me Expected 'End If' and not Expected 'End'.
 
dm_4ever thanks again for all of your help in the past. I can really say these forums are such a great asset to the VBS community, specially with people like yourself and EBGreen, he has helped me today a lot and I know that everyone’s time is very valuable. I have been trying to learn from posting to this forum and reading other peoples reply and suggestions, which I find more valuable then most of my text books.
 
 
Thanks,
 
Mike

(in reply to dm_4ever)
 
 
Post #: 16
 
 RE: Backup Script-copy - 1/11/2007 2:57:39 PM   
  dm_4ever


Posts: 2414
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
The 1st End If is to close out this If:        If filesys.FileExists("c:\DenServerBackup\Sunday.bkf") Then
The 2nd End If is to close out this If:       If datediff("d",File.DateLastModified,Now) > 7 Then   'How many days old the file is
The Next completes your:                        For Each File In Files

For more info on the For Each...Next statement you can look (http://msdn2.microsoft.com/en-us/library/tywtbxd0.aspx)

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 17
 
 RE: Backup Script-copy - 1/12/2007 2:02:53 AM   
  netman06

 

Posts: 105
Score: 0
Joined: 10/19/2006
Status: offline
Thanks, dm_4ever for the explantion that makes total sense and I'll check into the msdn link.

Mike


(in reply to dm_4ever)
 
 
Post #: 18
 
 RE: Backup Script-copy - 1/12/2007 4:04:06 AM   
  netman06

 

Posts: 105
Score: 0
Joined: 10/19/2006
Status: offline
Hello, EBGreen

I have completed this code, I made some changes to the ;;;, and had help from dm_4ever with my End If statement problem. I now have another issue, and need your help.

the problem is in the file names, I need to check to see if they are older then 7 days, if they are delete them, which will help my stay within the space limitations of my ext hard drive. what you did with the files names is awesome getting the create date or last modified into it will work great for me, but with my current code, I do not know how to get it to work with these file names. I do know how if it is a name like Sunday, but not SUNDAY20070111.bkf.

Also do you being a expert see anything in this code, after getting the file problem fixed, like the Path = "c:\DenServerBackup", should I maybe use s Dim statement?

I'll try to figure out what I would do and then let you correct me. Well I can list all files, but how do I read the date part of the file name?

Thanks,

Mike


      

(in reply to netman06)
 
 
Post #: 19
 
 RE: Backup Script-copy - 1/12/2007 4:26:33 AM   
  dm_4ever


Posts: 2414
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
I just realized. You don't need this line

Set filesys = CreateObject("Scripting.FileSystemObject")

You already created a FileSystemObject with your set fso.  You can replace filesys.FileExists with fso.FileExists.  You're currently only looking at the files located at the root of your path and not any of the subdirectories.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netman06)
 
 
Post #: 20
 
 
Page:   [1] 2 3   next >   >>