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
::-----------------------------------------------------------------------------------

:: -- 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%