Board logo

标题: [求助]自动备份问题 [打印本页]

作者: explore888     时间: 2007-11-30 21:19    标题: [求助]自动备份问题

sql2000的数据库 有20个bak文件。这20个是每天备份一个的。 文件名是以时间自动命名的。 我想找出最新的一个bak文件。备份到FTP上去 在FTP上删掉以前的 只保留最新的两个。

作者: fastslz     时间: 2007-11-30 21:31
自动命名的文件时间格式?

作者: explore888     时间: 2007-12-1 12:20
main_db_200711290800.BAK main_db_200711300800.BAK main_db_200712010800.BAK

作者: fastslz     时间: 2007-12-1 13:58
发错了 [ Last edited by fastslz on 2007-12-1 at 02:00 PM ]

作者: fastslz     时间: 2007-12-1 14:00
@echo off
for /f "delims=" %%a in ('dir /b /a-d /od D:\test\*.bak') do (
       for /f "tokens=2* delims=_" %%i in ('echo.%%a') do call :slz "%%i" "%%~nj" "%%a"
)
echo 最新日期%most% 对应文件名%file%
echo 次新日期%most1% 对应文件名%file1%
echo FTP没测试环境自己搞定
pause

:slz
set "fdate=%~2"
if not defined fdate goto:eof
set "filedate=%fdate:~2,-2%"
if not defined most set "most=0"
if %filedate% gtr %most% (
   set "most=%filedate%"
   set "most1=%most%"
   set "file=%~3"
   set "file1=%file%"
)
goto:eof

作者: explore888     时间: 2007-12-1 14:51
谢谢你 在登陆FTP后 怎么样 把这个变量上传上去 我用下面的实现了自动登陆 BAT批处理实现登陆FTP 假设登陆 ftp://192.168.0.1 ,登陆用户: admin ,密码: pass ,上传文件c:\00.txt , 需要文件c:\test.bat 和 c:\test.scr test.bat文件 ftp -n -s:test.scr 192.168.0.1 test.scr文件 user admin pass put c:\00.txt quit

作者: fastslz     时间: 2007-12-1 16:15
FTP我盲区,很难回答 或许你可以echo一个test.scr
@echo off
for /f "delims=" %%a in ('dir /b /a-d /od D:\test\*.bak') do (
       for /f "tokens=2* delims=_" %%i in ('echo.%%a') do call :slz "%%i" "%%~nj" "%%a"
)
echo 最新日期%most% 对应文件名%file%
echo 次新日期%most1% 对应文件名%file1%
>test.scr echo user admin
>>test.scr echo pass
>>test.scr echo put "%file%"
>>test.scr echo put "%file1%"
>>test.scr echo quit
ftp -n -s:test.scr 192.168.0.1
pause

:slz
set "fdate=%~2"
if not defined fdate goto:eof
set "filedate=%fdate:~2,-2%"
if not defined most set "most=0"
if %filedate% gtr %most% (
   set "most=%filedate%"
   set "most1=%most%"
   set "file=%~3"
   set "file1=%file%"
)
goto:eof
筛选删除FTP上我无能为力

作者: explore888     时间: 2007-12-1 16:59
可以在FTP机上搞批处理找出上传的按时间最新的两个文件保存起来。别的都删了。也可以啊