Jump to content

Recommended Posts

Posted

Wondering if someone could help with the following batch file...I would like it to keep a running log of dates. Now it overwrites the previous day, any help would be greatly appreciated. Thanks.

REM Start by setting the location to store the backup and the drive PowerSchool data resides on

SET POWERSCHOOL_SCRIPTS=D:

SET POWERSCHOOL_DRIVE=D:

SET POWERSCHOOL_BACKUP_FOLDER=D:\DailyBackup\

IF NOT EXIST %POWERSCHOOL_BACKUP_FOLDER% MD %POWERSCHOOL_BACKUP_FOLDER%

REM Capture the 3-character name of today

SET DAY=Default

FOR /F "TOKENS=1" %%A IN ('DATE/T') DO SET DAY=%%A

REM Sets the drive letter

%POWERSCHOOL_DRIVE%

Cd oradata\psproddb\data_pump_dir\

IF EXIST PowerSchool-%DAY%.dmp erase PowerSchool-%DAY%.dmp /q

%POWERSCHOOL_SCRIPTS%

cd\

Cd oracle\scripts

call EXPORT PSProdDB PowerSchool-%DAY%

%POWERSCHOOL_DRIVE%

Cd\

Cd oradata\psproddb\data_pump_dir\

Copy PowerSchool-%DAY%.dmp %POWERSCHOOL_BACKUP_FOLDER% /Y

Thanks again,

csd158


Posted

I'm guessing that your particular setup outputs DOW as part of Date/T, therefore every seven days you'll be overwriting the previous file. I'd suggest therefore that you use the full date instead, preferably in standard format or similar. YYYYMMDD.

Posted

Thank you for the reply. So would I replace that line with:

for /F "tokens=2-4 delims=/ " %i in ('date /t') do %k%i%j

I appreciate your help,

csd158

Posted

Try this VBS Script it just list the contents of D:\DailyBackup\, I have also included some date varibles. I have not included any code to copy or delete any files.

If it list the files that you want to copy or delete, post the file name and what you want done with it. I will then add the code to this script.

Save As MyBackup.vbs

Option Explicit
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim A1,Dy1, Dy2, Dy, Mn1, Mn2, Mn, Ts, Yr
'-> Date Varibles
Dy = Day(Now)
Dy1 = WeekdayName(Dy, True)
Dy2 = WeekdayName(Dy, False)
Mn = Month(Now)
Mn1 = MonthName(Mn, True)
Mn2 = MonthName(Mn, False)
Yr = Year(Now)
'-> If Varibles Are Less Then 10 Add A Zero
If Len(Dy) < 2 Then Dy = "0" & Dy
If Len(Mn) < 2 Then Mn = "0" & Mn
A1 = Mn & "_" & Mn1 & "_" & Dy1 & "_" & Dy
'-> Location Varibles
Dim Loc :Loc = "D:\DailyBackup\"
Dim Rpt :Rpt = Act.SpecialFolders("Desktop") & "\" & Yr & "_" & A1 & "_DailyBackup.log"

'-> Check To See If The Folder Exists
If Fso.FolderExists(Loc) Then
Set Ts = Fso.CreateTextFile(Rpt)
Ts.WriteLine Vbtab & "Date Varibles"
Ts.WriteLine _
" Dy = " & Dy & vbCrLf & _
" Dy1 = " & Dy1 & vbCrLf & _
" Dy2 = " & Dy2 & vbCrLf & _
" Mn = " & Mn & vbCrLf & _
" Mn1 = " & Mn1 & vbCrLf & _
" Mn2 = " & Mn2 & vbCrLf & _
" Yr = " & Yr & vbCrLf
Ts.WriteLine " Computer Name : " & Act.ExpandEnvironmentStrings("%ComputerName%")
Ts.WriteLine " Log File Name 1 : " & Rpt
Ts.WriteLine " Log File Name 2 : " & Replace(Rpt, A1, Mn2 & "_" & Dy2) & vbCrLf
Ts.WriteLine Space(5) & " Start Folder " & Loc
'-> Get Parent Folder And Sub Folder And All Files
SubFolder Fso.GetFolder(Loc)
Ts.Close
Act.Run("Notepad.exe " & Chr(34) & Rpt & Chr(34)),1,true
End If
'-> Process The Folder
Function SubFolder(Folder)
Dim Col, File
For Each File In Folder.files
Ts.WriteLine " File Name : " & File.Path
Next
For Each Col In Folder.subFolders
Ts.WriteLine Vbcrlf & Space(5) & " Sub Folder : " & Col.Path
SubFolder Col
Next
End Function

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...