标题: [问题求助] [已解决]将两个批处理合并改为VBS,并静默执行 [打印本页]
作者: brothersonline 时间: 2017-3-15 15:07 标题: [已解决]将两个批处理合并改为VBS,并静默执行
下面是两个定时远程备份服务器数据的批处理代码:请高手将此两个批处理合并,并改为可静默执行的VBS文件,谢过!
1、 复制实报服务器Oracle数据库备份文件到客户端批处理脚本- CLS
- @echo off
- echo ******************************************************************
- echo * 复制实报服务器Oracle数据库备份文件到客户端批处理脚本 *
- echo * By Zhangjian E-mail: *
- echo * %date:~0,10% %time:~0,8% *
- echo ******************************************************************
-
- @echo off
- mode con cols=80 lines=20
- title 远程复制程序
- color 04
- cls
-
- REM 设置备份目录
- set BACKUP_DIR=D:\BACKUP\SBSX_BACKUP
- set LOGTXT=LOG.RZ
-
- REM 取当前系统时间,可能因操作系统不同而取值不一样
- set CURDATE=%date:~0,4%%date:~5,2%%date:~8,2%
- set CURTIME=%time:~0,2%
-
- REM 小时数如果小于10,则在前面补0
- if "%CURTIME%"==" 0" set CURTIME=00
- if "%CURTIME%"==" 1" set CURTIME=01
- if "%CURTIME%"==" 2" set CURTIME=02
- if "%CURTIME%"==" 3" set CURTIME=03
- if "%CURTIME%"==" 4" set CURTIME=04
- if "%CURTIME%"==" 5" set CURTIME=05
- if "%CURTIME%"==" 6" set CURTIME=06
- if "%CURTIME%"==" 7" set CURTIME=07
- if "%CURTIME%"==" 8" set CURTIME=08
- if "%CURTIME%"==" 9" set CURTIME=09
- set FILTIME=%CURTIME%%time:~3,2%%time:~6,2%
- set LOGTIME=%CURTIME%:%time:~3,2%:%time:~6,2%
-
- REM 创建备份目录
- if not exist %BACKUP_DIR% md %BACKUP_DIR%
-
- REM 设备份目录为当前目录
- pushd %BACKUP_DIR%
- set CURDIR=%BACKUP_DIR%
-
- REM 删除超过10天的备份
- for /f "skip=10" %%i in ('dir/b/o-d *.DMP') do del %%i&&echo.%date:~0,10% %LOGTIME% 从%BACKUP_DIR%删除%%i>>%CURDIR%\%LOGTXT%
- for /f "skip=10" %%i in ('dir/b/o-d *.LOG') do del %%i&&echo.%date:~0,10% %LOGTIME% 从%BACKUP_DIR%删除%%i>>%CURDIR%\%LOGTXT%&&echo.------------------------------------------------------------------>>%CURDIR%\%LOGTXT%
-
- REM 映射服务器备份目录为本地S盘
- net use T: \\192.168.1.13\SBSX_BAK server2008 /user:administrator
- pushd t:\
-
- REM 复制最后一次备份文件到当前目录
- for /f %%i in ('dir/od/b *.DMP') do set dmpfile=%%i
- for /f %%i in ('dir/od/b *.LOG') do set logfile=%%i
- Xcopy /-y %dmpfile% %BACKUP_DIR%&&echo.%date:~0,10% %LOGTIME% 复制%dmpfile%到%BACKUP_DIR%>>%CURDIR%\%LOGTXT%
- Xcopy /-y %logfile% %BACKUP_DIR%&&echo.%date:~0,10% %LOGTIME% 复制%logfile%到%BACKUP_DIR%>>%CURDIR%\%LOGTXT%&&echo.------------------------------------------------------------------>>%CURDIR%\%LOGTXT%
-
- REM 断开映射
- net use T: /del /y
- exit
复制代码
2、复制服务器SQLServer数据库备份文件到客户端批处理脚本- CLS
- @echo off
- echo ******************************************************************
- echo * 复制服务器SQLServer数据库备份文件到客户端批处理脚本 *
- echo * By Zhangjian E-mail: *
- echo * %date:~0,10% %time:~0,8% *
- echo ******************************************************************
-
- @echo on
- mode con cols=80 lines=20
- title 远程复制程序
- color 04
- cls
-
- REM 设置备份目录
- set BACKUP_DIR=D:\BACKUP\GXSV4_BACKUP
- set LOGTXT=LOG.RZ
-
- REM 取当前系统时间,可能因操作系统不同而取值不一样
- set CURDATE=%date:~0,4%%date:~5,2%%date:~8,2%
- set CURTIME=%time:~0,2%
-
- REM 小时数如果小于10,则在前面补0
- if "%CURTIME%"==" 0" set CURTIME=00
- if "%CURTIME%"==" 1" set CURTIME=01
- if "%CURTIME%"==" 2" set CURTIME=02
- if "%CURTIME%"==" 3" set CURTIME=03
- if "%CURTIME%"==" 4" set CURTIME=04
- if "%CURTIME%"==" 5" set CURTIME=05
- if "%CURTIME%"==" 6" set CURTIME=06
- if "%CURTIME%"==" 7" set CURTIME=07
- if "%CURTIME%"==" 8" set CURTIME=08
- if "%CURTIME%"==" 9" set CURTIME=09
- set FILTIME=%CURTIME%%time:~3,2%%time:~6,2%
- set LOGTIME=%CURTIME%:%time:~3,2%:%time:~6,2%
-
- REM 创建备份目录
- if not exist %BACKUP_DIR% md %BACKUP_DIR%
-
- REM 设备份目录为当前目录
- pushd %BACKUP_DIR%
- set CURDIR=%BACKUP_DIR%
-
- REM 删除超过10天的备份
- for /f "skip=10" %%i in ('dir/b/o-d *.bak') do del %%i&&echo.%date:~0,10% %LOGTIME% 从%BACKUP_DIR%删除%%i>>%CURDIR%\%LOGTXT%
- for /f "skip=10" %%i in ('dir/b/o-d *.txt') do del %%i&&echo.%date:~0,10% %LOGTIME% 从%BACKUP_DIR%删除%%i>>%CURDIR%\%LOGTXT%&&echo.------------------------------------------------------------------>>%CURDIR%\%LOGTXT%
-
- REM for /f "skip=10 tokens=*" %%i in ('dir/b/o-d *.BAK') do rd "%%i"
- REM for /f "skip=10 tokens=*" %%i in ('dir/b/o-d *.TXT') do rd "%%i"
-
-
- REM 映射服务器备份目录为本地S盘
- net use U: \\192.168.1.13\GXS4_BAK server2008 /user:administrator
- pushd U:\
-
- REM 复制最后一次备份文件到当前目录
- for /f %%i in ('dir/od/b *.BAK') do set dmpfile=%%i
- for /f %%i in ('dir/od/b *.TXT') do set logfile=%%i
- Xcopy /-y %dmpfile% %BACKUP_DIR%&&echo.%date:~0,10% %LOGTIME% 复制%dmpfile%到%BACKUP_DIR%>>%CURDIR%\%LOGTXT%
- Xcopy /-y %logfile% %BACKUP_DIR%&&echo.%date:~0,10% %LOGTIME% 复制%logfile%到%BACKUP_DIR%>>%CURDIR%\%LOGTXT%&&echo.------------------------------------------------------------------>>%CURDIR%\%LOGTXT%
-
- REM 断开映射
- net use U: /del /y
- exit
复制代码
作者: yu2n 时间: 2017-3-15 22:10
0.vbs- CreateObject("WScript.Shell").run "cmd /c ""c:\1.bat""", 0, False
- CreateObject("WScript.Shell").run "cmd /c ""c:\2.bat""", 0, False
复制代码
作者: brothersonline 时间: 2017-3-15 22:14
回复 2# yu2n
谢谢您的回复,我是想直接将两个批处理做成VBS,是否可行?
作者: yu2n 时间: 2017-3-15 22:17
回复 3# brothersonline
可行。
你得找个人帮你一行一行改。或者你自己花点时间改。
作者: brothersonline 时间: 2017-3-15 22:23
回复 4# yu2n
谢谢!看来我得好好学习一下了。
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |