[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] 共享脚本:压缩sql数据库后上传到ftp

本帖最后由 qwertl 于 2011-11-25 11:25 编辑

win2003+mssql server)压缩sql数据库后上传到ftp:

在论坛学习到的,给有用得着的参考下。
代码如下:


net stop  SQLSERVERAGENT
ping -n 10 127.1>nul
net stop MSSQLSERVER
ping -n 10 127.1>nul
"C:\Program Files\7-Zip\7z.exe" a -p111222 d:\rardata\sql1_%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%.7z d:\sqldata\sql1*.*
"C:\Program Files\7-Zip\7z.exe" a -p111222 d:\rardata\sql2_%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%.7z d:\sqldata\sql2.mdf d:\sqldata\sql2_log.ldf
ping -n 10 127.1>nul
net start MSSQLSERVER
ping -n 10 127.1>nul
net start SQLSERVERAGENT
d:\software\autodel 60 d:\rardata
set desfolder=d:\rardata
dir %desfolder% /b /aa-d>nul 2>nul
if %errorlevel% equ 1 (
  echo No archiving file to FTP
  ping -n 10 127.1>nul
  goto :eof
)
set FtpFile=%temp%\TempAcc.txt
>"%FtpFile%" echo account
>>"%FtpFile%" echo pwd
>>"%FtpFile%" echo cd subdir
>>"%FtpFile%" echo bin
for /f "tokens=*" %%a in ('dir "%desfolder%" /b /aa-d') do (
  >>"%FtpFile%" echo put "%desfolder%\%%a"
)
>>"%FtpFile%" echo bye
echo. >>d:\software\arlog.txt
echo sql包上传ftp时间:%date% %time%>>d:\software\arlog.txt
ftp -v -i -s:"%FtpFile%" ftpSRV_IP>>d:\software\arlog.txt
echo. >>d:\soft\arlog.txt
time /t >>d:\software\arlog.txt
echo sql压缩包数据上传FTP完成== >>d:\software\arlog.txt
echo. >>d:\software\arlog.txt
echo. >>d:\software\arlog.txt
ping -n 2 127.1>nul
attrib -a "%desfolder%"\*.*
ping -n 6 127.1>nul
delete %temp%\TempAcc.txt
exit

返回列表