Operating System - Microsoft
1748123 Members
3314 Online
108758 Solutions
New Discussion юеВ

Re: Monthly Backups....dos style =)

 
SOLVED
Go to solution
Ganesh Babu
Honored Contributor

Re: Monthly Backups....dos style =)

Hi Monty,
Sorry i was tied up in a work and not able to post the script faster...

Here it is now..

copy the below code to some filename.wsf for ex., c:\copyfiles.wsf


<script language="VBScript">

dim FSO
dim objsourcefolder
dim filecollection
dim filepath
dim oWS
dim Lastmonth
dim returncode
dim scmd

folder_path="h:\"

Set FSO = CreateObject("Scripting.FileSystemObject")
set oWS = CreateObject("Wscript.Shell")

Set objSourceFolder = FSO.GetFolder(folder_path)
Set fileCollection = objSourceFolder.files

For Each filePath in fileCollection
Lastmonth = CInt(DateDiff("m",filePath.DateLastModified,Now))

scmd = "c:\Program Files\Winzip\wzzip c:\backup\Daily\h" & month(now) & day(now) & year(now) & ".zip -r -p -t "

If Lastmonth = 1 Then

scmd = scmd & folder_path & filepath.name

'WScript.Echo scmd
returnCode = oWS.Run(scmd, 0, true)

End If
next

dim subfolderscoll
dim subfol

set subfolderscoll = objsourcefolder.subfolders

for each subfol in subfolderscoll

Set fileCollection = subfol.files

For Each filePath in fileCollection

Lastmonth = CInt(DateDiff("m",filePath.DateLastModified,Now))

scmd = "c:\Program Files\Winzip\wzzip c:\backup\Daily\h" & month(now) & day(now) & year(now) & ".zip -r -p -t "

If Lastmonth = 1 Then

scmd = scmd & folder_path & subfol.name & "\" & filepath.name

' WScript.Echo scmd
returnCode = oWS.Run(scmd, 0, true)

End If
next
next

</script>


run this script as

CScript.exe C:\copyfiles.wsf


Let me know how it goes..

Ganesh
Monty Lovell
Advisor

Re: Monthly Backups....dos style =)

WOW Thanks Ganesh! I'll have to give it a whirl and Jon's as well. I've been totally swapped here today so I'm hopin' to try it in the mornin.
Thanks again for all your work you guys =)
Totally appreciated!
Monty.
Monty Lovell
Advisor

Re: Monthly Backups....dos style =)

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\lovell.HMFH>Cscript.exe c:\backup\sys\copyfiles.wsf

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

c:\backup\sys\copyfiles.wsf(31, 2) (null): The system cannot find the file speci
fied.

Hi Ganesh. I just tried it, maybe I gave you the wrong information...or I tried to run it incorrectly. I copied this from the DOS window. Does the script file look for all files within the H: drive or is it looking through the already made daily zip files?
I will totally understand if you just want to drop this...sorry for this.
Ganesh Babu
Honored Contributor

Re: Monthly Backups....dos style =)

Hi Monty,
I think the issue is the system did not take the long folder name..

change this statement in the file

scmd = "c:\Program files\Winzip\wzzip c:\backup\Daily\h" & month(now) & day(now) & year(now) & ".zip -r -p -t "

to

scmd = "c:\Progra~1\Winzip\wzzip.exe c:\backup\Daily\h" & month(now) & day(now) & year(now) & ".zip -r -p -t "

this statement is there 2 times.. so make sure u replace it in both the placess..

Test it out and let me if it works..

Ganesh
Monty Lovell
Advisor

Re: Monthly Backups....dos style =)

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\lovell.HMFH>CScript.exe c:\backup\sys\copyfile.wsf
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

c:\backup\sys\copyfile.wsf(31, 2) (null): The system cannot find the file specif
ied.

Hi Ganesh - I changed it to "~1" both places and it gave me this again. Do you think I'm giving you some wrong data, variables, etc.? Again, if you want to cut your losses I will more than understand. Thanks for all your time in this.
Monty =)
Ganesh Babu
Honored Contributor

Re: Monthly Backups....dos style =)

Hi Morty,
The issue is here only

scmd = "c:\Progra~1\Winzip\wzzip.exe c:\backup\Daily\h" & month(now) & day(now) & year(now) & ".zip -r -p -t "

either the wzzip.exe directory is wrong or the path where it is going to create the zip file might be wrong

1) what is the path of wzzip.exe?
2) does c:\backup\Daily\ directory exists??

Ganesh
Monty Lovell
Advisor

Re: Monthly Backups....dos style =)

Howdy - Yep those are the right directory names. I'm curious though does this script search the existing zip files on my c: drive or all the files on H: drive?
I'm hoping to write a zip file that searches all files on H: drive.
Hope I didn't throw a wrench in the gears.
Monty =)
Ganesh Babu
Honored Contributor

Re: Monthly Backups....dos style =)

Hi Monty,
i want u to run this script

job debug="true">
<script language="VBScript">

dim FSO
dim objsourcefolder
dim filecollection
dim filepath
dim oWS
dim Lastmonth
dim returncode
dim scmd

folder_path="h:\"

Set FSO = CreateObject("Scripting.FileSystemObject")
set oWS = CreateObject("Wscript.Shell")

Set objSourceFolder = FSO.GetFolder(folder_path)
Set fileCollection = objSourceFolder.files

For Each filePath in fileCollection
Lastmonth = CInt(DateDiff("m",filePath.DateLastModified,Now))

scmd = "c:\Progra~1\Winzip\wzzip c:\backup\Daily\h" & month(now) & day(now) & year(now) & ".zip -r -p -t "

If Lastmonth = 1 Then

scmd = scmd & folder_path & filepath.name

WScript.Echo scmd
'returnCode = oWS.Run(scmd, 0, true)

End If
next

</script>


when it runs it will display a message box with the output of the scmd variable. This is the command which has to run to create the zipfile.

So copy that or note it down and run it from where u running the script. And tell me whether there were any errors. If there are any errors. Let me know..

Ganesh
Monty Lovell
Advisor

Re: Monthly Backups....dos style =)

Hi Ganesh - Sure here's the output from this script. Hope this helps, and thanks for your persistance! =)
Monty

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\lovell.HMFH>CScript.exe c:\backup\sys\test.wsf
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

c:\backup\sys\test.wsf(37, 4) Windows Script Host: The end tag does not have a
corresponding start tag : job

>
Monty Lovell
Advisor

Re: Monthly Backups....dos style =)

Oh yeh just to let you know I'll be out of the office all next week so if you want we can take this back up on the 26th when I get back.