简体   繁体   中英

Move rename and zip files

My oracle server is in windows 2008 64 bit . I need to move listner.log files to

 E:\DBA_CMDS\Maintenance_Tasks\ClearListenerLog\ArchivedListenerLogs

from

E:\OracleGrid\11.2.0\grid\log\diag\tnslsnr\enctcorl010\listener\alert\

I need to rename that file as currentdate.log and my log directory and log name is

E:\DBA_CMDS\Maintenance_Tasks\ClearListenerLog\ClearListenerLog.log

I need to zip the file after i rename it and my 7-ZIP is installed in

C:\Program Files\7-Zip\7Z.EXE. 

I will appreciate if some one can help me out to write all this in batch script as I am new to windows script.

Test this:

@echo off
set "source=E:\OracleGrid\11.2.0\grid\log\diag\tnslsnr\enctcorl010\listener\alert"
set "target=E:\DBA_CMDS\Maintenance_Tasks\ClearListenerLog\ArchivedListenerLogs"

for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "datestamp=%DD%%MM%%YY%" & set "timestamp=%HH%%Min%%Sec%"


setlocal enabledelayedexpansion
set c=0
for %%a in ("%source%\*.log") do (
set /a c+=1
"C:\Program Files\7-Zip\7Z.EXE" a "%target%\listener_%datestamp%_!c!.7z" "%%a"
if not errorlevel 1 del "%%a"
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM