hi,,,,pleas can any one help,,

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
agha
Posts: 18
Joined: 10 Sep 2012 01:32

hi,,,,pleas can any one help,,

#1 Post by agha » 10 Sep 2012 01:44

we create the following batch to take a backup from our CRM application
its works but cant save ,,,once it finish from runing its delete every thing


REM Change the directory to the below local path
set LOCALPATH=C:\UBABACKUP\
set NTLOCATION=\\192.168.2.200\UBACRMBackup
set ASPPATH=C:\Program Files (x86)\Sage\CRM\UBA



FOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%B
FOR /F "tokens=1-3 delims=/-" %%A IN ("%Today%") DO (
SET DayMonth=%%A
SET MonthDay=%%B
SET Year=%%C
)



set UBAFOLDER=%UBACRMFullBackup %MonthDay%-%DayMonth%-%Year%
set UBAFOLDER2=%LOCALPATH%UBACRMFullBackup %MonthDay%-%DayMonth%-%Year%
set DBBACKUP=%MonthDay%-%DayMonth%-%Year%.bkp
set DBBACKUPZIP="UBACRMFullBackup %MonthDay%-%DayMonth%-%Year%.zip"
set DBBACKUPZIP2="UBACRMFullBackup %MonthDay%-%DayMonth%-%Year%.zip"
set DBNAME=UBA

echo %MonthDay%-%DayMonth%-%Year%
md "%UBAFOLDER2%"
cd "%UBAFOLDER2%"


xcopy "%ASPPATH%*.*" "%UBAFOLDER2%\ASP*.*" /d /y /s

cd "%UBAFOLDER2%"
cd..
zip -r %DBBACKUPZIP% "%UBAFOLDER2%\ASP*.*"


rd "%UBAFOLDER2%" /s /q

copy %DBBACKUPZIP% "%NTLOCATION%"



SETLOCAL ENABLEEXTENSIONS

set "days=30"
set "srcpath=%LOCALPATH%"
set "srcpath2=%NTLOCATION%"

call:jdate tnow "%date%"
for /f "tokens=*" %%F in ('dir /b "%srcpath%.\*.*"') do (
call:DeleteIfOld "%%~$srcpath:F" "%days%" "%tnow%"
)

call:jdate tnow "%date%"
for /f "tokens=*" %%F in ('dir /b "%srcpath2%.\*.*"') do (
call:DeleteIfOld "%%~$srcpath2:F" "%days%" "%tnow%"
)

ECHO.
GOTO:EOF






::-----------------------------------------------------------------------------------
::-- Functions start below here
::-----------------------------------------------------------------------------------


:DeleteIfOld name days tnow -- deletes file or directory if older than given number of days
:: -- name [in] - name of file or directory
:: -- days [in] - number of days to expire
:: -- tnow [in] - today's date in julia days

SETLOCAL
set "days=%~2"
set "tnow=%~3"
call:ftime tfile "%~1"
set /a "diff=tnow-tfile"
if %diff% LEQ %days% EXIT /b %ERRORLEVEL
set "attr=%~a1"
rem ECHO.%attr%, %attr:~0,1%, %~nx1 is %diff% days old
if /i "%attr:~0,1%"=="d" (
rd /Q /S "%~1"
) ELSE (
del /Q "%~1"
)
EXIT /b %ERRORLEVEL%


:ftime JD filename attr -- compares the time of two files, succeeds if condition is met, fails otherwise
:: -- JD [out] - valref file time in julian days
:: -- attr [in,opt] - time field to be used, creation/last-access/last-write, see 'dir /?', i.e. /tc, /ta, /tw, default is /tw

SETLOCAL
set file=%~2
set attr=%~3
if "%attr%"=="" set attr=/tw
for /f %%a in ('"dir %attr% /-c "%file%"|findstr "^^[0-1]""') do set T=%%a
call:jdate JD "%T%"
( ENDLOCAL & REM RETURN VALUES
IF "%~1" NEQ "" (SET %~1=%JD%) ELSE (echo.%JD%)
)
EXIT /b %ERRORLEVEL%


:jdate JD DateStr -- converts a date string into julian day number
:: -- JD [out] - julian days
:: -- DateStr [in] - date string, i.e. "03/31/2006" or "Fri 03/31/2006"

SETLOCAL ENABLEDELAYEDEXPANSION
set DateStr=%~2
set DateStr=%DateStr:~-10%&rem consider only the last 10 characters
for /f "tokens=1-3 delims=/ " %%a in ("%DateStr%") do (
set /a YYYY=1%%c-10000
set /a MM=1%%a-100
set /a DD=1%%b-100
)
call:date2jdate JD "%YYYY%" "%MM%" "%DD%"
( ENDLOCAL & REM RETURN VALUES
IF "%~1" NEQ "" (SET %~1=%JD%) ELSE (echo.%JD%)
)
EXIT /b %ERRORLEVEL%


:date2jdate JD YYYY MM DD -- converts a gregorian calender date into julian day format
:: -- JD [out] - julian days
:: -- YYYY [in] - gregorian year, i.e. 2006
:: -- MM [in] - gregorian month, i.e. 12 for december
:: -- DD [in] - gregorian day, i.e. 31
:: -- reference

SETLOCAL ENABLEDELAYEDEXPANSION
set YYYY=%~2
set MM=%~3
set DD=%~4
set /a I=%YYYY%
set /a J=%MM%
set /a K=%DD%
set /a JD=K-32075+1461*(I+4800+(J-14)/12)/4+367*(J-2-(J-14)/12*12)/12-3*((I+4900+(J-14)/12)/100)/4
( ENDLOCAL & REM RETURN VALUES
IF "%~1" NEQ "" (SET %~1=%JD%) ELSE (echo.%JD%)
)
EXIT /b %ERRORLEVEL%


:jdate2date JD YYYY MM DD -- converts julian days into gregorian date format
:: -- JD [in] - julian days
:: -- YYYY [out] - gregorian year, i.e. 2006
:: -- MM [out] - gregorian month, i.e. 12 for december
:: -- DD [out] - gregorian day, i.e. 31
:: -- reference ::source http://www.DosTips.com
SETLOCAL ENABLEDELAYEDEXPANSION
set /a L= %~1+68569
set /a N= 4*L/146097
set /a L= L-(146097*N+3)/4
set /a I= 4000*(L+1)/1461001
set /a L= L-1461*I/4+31
set /a J= 80*L/2447
set /a K= L-2447*J/80
set /a L= J/11
set /a J= J+2-12*L
set /a I= 100*(N-49)+I+L
set /a YYYY= I
set /a MM= J
set /a DD= K
( ENDLOCAL & REM RETURN VALUES
IF "%~2" NEQ "" SET %~2=%YYYY%
IF "%~3" NEQ "" SET %~3=%MM%
IF "%~4" NEQ "" SET %~4=%DD%
)
EXIT /b %ERRORLEVEL%

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: hi,,,,pleas can any one help,,

#2 Post by foxidrive » 10 Sep 2012 04:44

If you take the REM out here, does it display what it should properly?

rem ECHO.%attr%, %attr:~0,1%, %~nx1 is %diff% days old

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: hi,,,,pleas can any one help,,

#3 Post by Dos_Probie » 10 Sep 2012 07:29

What OS are you running?

agha
Posts: 18
Joined: 10 Sep 2012 01:32

Re: hi,,,,pleas can any one help,,

#4 Post by agha » 11 Sep 2012 00:32

hi foxidrive
i take the REM out its still cant be save;;

hello Dos_Probie
we use windows server 2007 edition sevice pack 2
------------------------------------------------------------
the main problem is it cant be save after take the backup sucessfully ,,i mean i can see the files through process but its remove once it finish

agha
Posts: 18
Joined: 10 Sep 2012 01:32

Re: hi,,,,pleas can any one help,,

#5 Post by agha » 18 Sep 2012 01:35

hello; its an urgent issue
any update from dostips technical team or from any one know the solution for my case,,, regarding this issue will be a highly appreciate

thanks alot

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: hi,,,,pleas can any one help,,

#6 Post by foxidrive » 18 Sep 2012 02:23

You %date% format could be incorrect for the routines you have used.

agha
Posts: 18
Joined: 10 Sep 2012 01:32

Re: hi,,,,pleas can any one help,,

#7 Post by agha » 18 Sep 2012 02:34

so what is the date format i suppose to use????

agha
Posts: 18
Joined: 10 Sep 2012 01:32

Re: hi,,,,pleas can any one help,,

#8 Post by agha » 18 Sep 2012 02:34

so what is the date format i suppose to use????

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: hi,,,,pleas can any one help,,

#9 Post by foxidrive » 18 Sep 2012 02:53

I don't know - You didn't describe your batch file - you just posted a whole mess of routines and said 'fix it'.

That means we have to read code that doesn't work and try to decipher what you want to do - because you didn't tell us what it is meant to do... and who wants to do that?

agha
Posts: 18
Joined: 10 Sep 2012 01:32

Re: hi,,,,pleas can any one help,,

#10 Post by agha » 18 Sep 2012 03:02

hello foxidrive
first of all i didnt say fix it and your not not obliged to help me or to help any one ,,,,then you have to know what is client care mean before you try to helo any one,,,
finally its not a big deal or problem if you say i dot no its better more than what you said,,
any way its seems your so helpfull and a kind of person ,,,,thanks alot

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: hi,,,,pleas can any one help,,

#11 Post by foxidrive » 18 Sep 2012 11:48

I note that you still haven't described the batch file, and what it is that you want it to do.


agha wrote:then you have to know what is client care mean before you try to helo any one,,,


You, my friend, have to respect the people that are doing work on your behalf.

Be very aware that you pasted a page of code and routines without an explanation of what the code is meant to do, and you expected someone to fix it. :roll:

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: hi,,,,pleas can any one help,,

#12 Post by abc0502 » 18 Sep 2012 13:20

Hi, agha
We always see topics just like yours, with a problem in a batch they made or found and have problems, and we spend few days just keep asking question to get full understanding to that problems.
after we did we can solve the problem and if the user posted all information he know about the problem from the first time we could have solved the problem in no time

That's why Foxidrive made this Topic so any new user understand that information about any problem is needed to solve any problem they have.

Till now all what you did is posting a 173 line code, and explained it in 2 lines
This is very short explanation for a batch with that long, please provide all information about this batch and your problem

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: hi,,,,pleas can any one help,,

#13 Post by foxidrive » 18 Sep 2012 13:53

Thanks abc0502.


To the OP: It seems to me that this part is working ok, and your problems have to do with the part that follows - which apparently is meant to remove older backups.


Code: Select all

REM Change the directory to the below local path
set LOCALPATH=C:\UBABACKUP\
set NTLOCATION=\\192.168.2.200\UBACRMBackup
set ASPPATH=C:\Program Files (x86)\Sage\CRM\UBA



FOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%B
FOR /F "tokens=1-3 delims=/-" %%A IN ("%Today%") DO (
SET DayMonth=%%A
SET MonthDay=%%B
SET Year=%%C
)



set UBAFOLDER=%UBACRMFullBackup %MonthDay%-%DayMonth%-%Year%
set UBAFOLDER2=%LOCALPATH%UBACRMFullBackup %MonthDay%-%DayMonth%-%Year%
set DBBACKUP=%MonthDay%-%DayMonth%-%Year%.bkp
set DBBACKUPZIP="UBACRMFullBackup %MonthDay%-%DayMonth%-%Year%.zip"
set DBBACKUPZIP2="UBACRMFullBackup %MonthDay%-%DayMonth%-%Year%.zip"
set DBNAME=UBA

echo %MonthDay%-%DayMonth%-%Year%
md "%UBAFOLDER2%"
cd "%UBAFOLDER2%"


xcopy "%ASPPATH%*.*" "%UBAFOLDER2%\ASP*.*" /d /y /s

cd "%UBAFOLDER2%"
cd..
zip -r %DBBACKUPZIP% "%UBAFOLDER2%\ASP*.*"


rd "%UBAFOLDER2%" /s /q

copy %DBBACKUPZIP% "%NTLOCATION%"

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: hi,,,,pleas can any one help,,

#14 Post by abc0502 » 18 Sep 2012 13:57

@ Foxidrive, i didn't examin the section yoiu post, but till he tell us what files was deleted and from where, i think the backup files is what is keep deleting.
so @agha,
you said:
agha wrote:once it finish from runing its delete every thing

do you mean it delete all from the NTlocation?
and what kind of files is in NTlocation and Localpath, folders and files or files only?


and about this section:

Code: Select all

SETLOCAL ENABLEEXTENSIONS

set "days=30"
set "srcpath=%LOCALPATH%"
set "srcpath2=%NTLOCATION%"

call:jdate tnow "%date%"
for /f "tokens=*" %%F in ('dir /b "%srcpath%.\*.*"') do (
call:DeleteIfOld "%%~$srcpath:F" "%days%" "%tnow%"
)

call:jdate tnow "%date%"
for /f "tokens=*" %%F in ('dir /b "%srcpath2%.\*.*"') do (
call:DeleteIfOld "%%~$srcpath2:F" "%days%" "%tnow%"
)

ECHO.
GOTO:EOF

this is the one that is responsible for deleting the files, and the main propose is to delete the files in srcpath and srcpath2 if older than a given day.

is it ok if we replace this part with another code?

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: hi,,,,pleas can any one help,,

#15 Post by Dos_Probie » 18 Sep 2012 18:00

hello; its an urgent issue
any update from dostips technical team or from any one know the solution for my case,,, regarding this issue will be a highly appreciate


One of my pet peeves on here is when people create a one time account and
desperately seek help and when help is give we never hear from them again ..
"The more Details you give the better Answers you will get!" :mrgreen:

Post Reply