Board logo

标题: 备份的批处理 [打印本页]

作者: qwertl     时间: 2009-5-22 12:25    标题: 备份的批处理

查找本机的accon.dat文件,可能在不同盘符的不同路径,也可能有几个,现要编个批处理,能较高效的搜索找到这个文件的完整路径,然后将其也有可能多个均压缩到F:\backup下,以当前日期为文件名的压缩包,要不出现任何窗口提示

再做该批处理做计划任务.

请说说不同的方法
作者: Hanyeguxing     时间: 2009-5-22 14:09
批处理使用backup.bat:
@echo off
erase %temp%\han.txt>nul 2>nul
for %%i in (C:,D:,E:,F:) do dir %%i /b/s|findstr /i accon.dat >>%temp%\han.txt
for /f "delims=" %%j in (%temp%\han.txt) do winrar.exe A -CFG- -IBCK-INUL -m5 -agYYYYMMDD F:\backup\ %%j

隐藏cmd 窗口使用backup.vbs
CreateObject("Wscript.Shell").run "F:\backup\backup.bat",0

任务计划使用
sc config Schedule start= auto & net start Schedule
at 20:05 F:\backup\backup.vbs

[ Last edited by Hanyeguxing on 2009-5-22 at 14:11 ]
作者: Hanyeguxing     时间: 2009-5-22 14:14
说明
winrar.exe,根据情况,一般需要指定他的路径
YYYY 定义4位数字的年
MM 定义2位数字的月
DD 定义2位数字的日
如果在格式化字符串的第一个字符是‘+’,日期字符串和基本压缩文件名位置交换,所以日期将在压缩文件名之前。
开关 -INUL - 禁用错误信息
开关 -CFG- - 忽略默认配置和环境变量
开关 -IBCK - 在后台运行 WinRAR
开关 -M<n> - 设置压缩方式
任务计划可以用at,也可以使用Schtasks
作者: tireless     时间: 2009-5-23 10:39
backup.bat
@echo of
setlocal enabledelayedexpansion
for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
  if exist %%a: set Files=!Files! "%%a:\accon.dat"
)
"C:\Program Files\winrar\rar.exe" a -r -inul -agYYYYMMDD F:\backup\ !Files!
添加计划任务:
sc config Schedule start= auto & net start Schedule
at 20:05 "backup.bat"

作者: qwertl     时间: 2009-5-23 11:09
二楼的方法dir %%i /b/s |findstr /i accon.dat 太慢了   
用everything的命令提示符es.exe速度要快多了  

http://www.voidtools.com/    附上everything  及es.exe下载网址



楼上的好象只是找根目录下的批处理

[ Last edited by qwertl on 2009-5-23 at 11:22 ]
作者: tireless     时间: 2009-5-23 11:47    标题: Re 5 楼

会搜索子目录。

  Quote:
@echo of
setlocal enabledelayedexpansion
for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
  if exist %%a: set Files=!Files! "%%a:\accon.dat"
)
"C:\Program Files\winrar\rar.exe" a -r -inul -agYYYYMMDD F:\backup\ !Files!

[ Last edited by tireless on 2009-6-4 at 03:50 ]
作者: qwertl     时间: 2009-6-4 00:35
for %%i in (C:,D:,E:,F:) do dir %%i /b/s|findstr /i accon.dat >>%temp%\han.txt

这句如果要加多个文件accon.cfg在一句命令里要怎样写?
作者: tireless     时间: 2009-6-4 03:42    标题: re 7 楼


(for %%i in (c d e f) do dir /b/s %%i:\accon.dat %%i:\accon.cfg 2>nul)>%temp%\han.txt

dir/b/s c: d: e: f:|findstr /IL "accon.dat accon.cfg" > %temp%\han.txt
或者把 4 楼的改成:

  Quote:
@echo of
setlocal enabledelayedexpansion
for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
  if exist %%a: set Files=!Files! "%%a:\accon.dat" "%%a:\accon.cfg"
)
"C:\Program Files\winrar\rar.exe" a -r -inul -agYYYYMMDD F:\backup\ !Files!

[ Last edited by tireless on 2009-6-4 at 03:56 ]
作者: qwertl     时间: 2009-6-4 23:27
谢谢楼上的高人.
作者: 不得不爱     时间: 2009-6-5 00:25
我来个简单点的,就一个命令搞定!
"C:\Program Files\winrar\rar.exe" a -r -inul -agYYYYMMDD F:\backup\ -naccon.dat -naccon.cfg  c: d: e: f: g: h:  i: j: k: l: m: n: o: p: q: r: s: t: u: v: w: x: y: z:
[ Last edited by 不得不爱 on 2009-6-5 at 03:21 ]
作者: tireless     时间: 2009-6-5 00:52


  Quote:
Originally posted by 不得不爱 at 2009-6-5 12:25 AM:
我来个简单点的,就一个命令搞定!
[code]"C:\Program Files\winrar\rar.exe" a -r -inul -agYYYYMMDD F:\backup\ -naccon.dat -naccon.cfg text c: d: e: f: g: h:  i: j: k: l: m:  ...

经测试,只能添加根目录的文件;text 是多余的
作者: 不得不爱     时间: 2009-6-5 03:24
可是我测试是没有问题的啊,-r就会搜索子目录啊 ,不会是你的rar不支持-r吧?(text 的确是多余的)
作者: tireless     时间: 2009-6-5 05:15    标题: 我测试的结果:

只添加了根目录的 a.txt:
"C:\Program Files\winrar\rar.exe" a -r -inul -agYYYYMMDD .\root_ -na.txt d: g:
会添加包括子目录的 a.txt:
"C:\Program Files\winrar\rar.exe" a -r -inul -agYYYYMMDD .\sub_ d:\a.txt g:\a.txt
[ Last edited by tireless on 2009-6-5 at 05:18 ]
作者: 不得不爱     时间: 2009-6-6 07:13
知道在这么回事了 ,原来是rar(在"C:\Program Files\winrar\rar.exe" a -r -inul -agYYYYMMDD .\root_ -na.txt d: g:这个命令里)读取当前盘时会只读当前目录树!
应该修改为:
"C:\Program Files\winrar\rar.exe" a -r -inul -agYYYYMMDD F:\backup\ -naccon.dat -naccon.cfg  c:\ d:\ e:\ f:\ g:\ h:\  i:\ j:\ k:\ l:\ m:\ n:\ o:\ p:\ q:\ r:\ s:\ t:\ u:\ v:\ w:\ x:\ y:\ z:\
这样就不会出错了!
作者: tireless     时间: 2009-6-6 12:46    标题: re 14 楼

我这里一样只打包了根目录的文件。
作者: 不得不爱     时间: 2009-6-6 22:30
F:\backup\这个目录存在吗 ,如果没有存在就建立1个 或者修改为.\试下,反正我这是没有什么问题的 ,另外你的其他的目录里有相应的文件吗?
作者: tireless     时间: 2009-6-7 04:03    标题: re 16 楼

我这里测试 rar 3.7 和 rar 3.9 都不能打包子目录的文件。

其他人也测试下?
作者: 不得不爱     时间: 2009-6-7 06:35
我这是rar 3.51都可以打包子目录的文件啊 ,是不是版本问题,如果是的话就是一个bug
作者: tireless     时间: 2009-6-7 11:37
果然,rar 3.51 就可以。
作者: 不得不爱     时间: 2009-6-7 21:42
那就肯定是bug了!