Question : How to create a log file (log_<date>.txt) for a DOS batch script

Hello Experts,
We have inherited an application whose database gets restored every week. The restore process is invoked by a dos batch file which is scheduled to run once a week. (see code snippet). The problem we have right now is that the scheduled task says it was successful but the restore history (MSDB..RestoreHistory)  was not. Also the script doesn't have any logging mechanism which therefore we could not determine what really happened whether the steps it's supposed to do was successful or not.
I gues what i wanted to do was to include an output text file (log_<date>.txt) on each steps inside the script. Is this possible? Would anyone show/assist/refer us how...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
IF NOT Exist "D:\ETL\APP.bak" GOTO End
copy "D:\ETL\APP.bak" "C:\App_restore\" /y
::SET VARIABLES
set DBNAME=NAMEOFDATABASEBEINGRESTORED
set DBDIRECTORY=C:\Program Files\Microsoft SQL Server\MSSQL\Data

TITLE Restoring Student_Data_Mart Database

::PUT DATABASE IN SINGLE USER MODE TO ALLOW RESTORE
osql -E -d master -Q "alter database App_Business_DB set single_user with rollback immediate"

::RESTORE DATABASE
osql -E -d master -Q "restore database App_Business_DB from disk='C:\App_restore\APP.bak' WITH replace,Move 'App_Business_Profile' TO 'C:\SQL_DATA\APPSDB\App_Business_Profile.mdf',  MOVE 'App_Business_Profile_Log' TO 'C:\SQL_DATA\APPSDB\App_Business_Profile_2.ldf'"

::GRANT PERMISSION TO ASPNET USER
osql -E -d App_Business_DB -Q "sp_grantdbaccess 'business\svcappbussql'"
osql -E -d App_Business_DB -Q "sp_addrolemember 'db_owner', 'business\svcappbussql'"

::RESTORE TO MULTI USER
osql -E -d master -Q "alter database App_Business_DB set multi_user"

del "C:\App_restore\APP.bak" 
del "D:\ETL\APP.bak"

:End
ECHO Finished

Answer : How to create a log file (log_<date>.txt) for a DOS batch script

Use this instead
1:
2:
3:
4:
   Dim rs As Recordset
   Set rs = frm.Recordset
   rs.Delete
   rs.Requery
Random Solutions  
 
programming4us programming4us