找回密码
 加入
搜索
查看: 4445|回复: 14

[AU3基础] 数据在指定时间备份并压缩为系统时间命名的压缩文件

  [复制链接]
发表于 2010-6-24 15:40:24 | 显示全部楼层 |阅读模式
本帖最后由 howie530_8 于 2010-6-25 21:04 编辑

比如在每天下午2:00把D:\t1的数据备份到D:\t2并压缩为‘aa_20100624_1400.rar’
$time1=1652
While 1
                Switch @HOUR & @MIN
                         Case $time1 to $time1
$TIME = @YEAR&@MON&@MDAY &"_" &@HOUR&@MIN&@SEC
;把D:\t1目录拷贝到D:\t2下并以系统时间命名
DirCopy("D:\t1", "D:\t2"&"TDData_"&$time)
FileInstall("winrar.exe","winrar.exe")
Run("WinRAR.exe", "", @SW_HIDE)
EndSwitch
        ;50S循环一次
        sleep(50000)
WEnd
但是压缩想用winrar没有实现、请高手帮忙,谢谢!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-6-24 15:48:30 | 显示全部楼层
围观处女贴……
不见提问字样,lZ是要分享源码吗?
 楼主| 发表于 2010-6-24 16:28:02 | 显示全部楼层
回复 2# afan


    恩、是的
发表于 2010-6-24 16:30:20 | 显示全部楼层
回复 3# howie530_8


    晕~ 那你就分享啊,到时候转到源码区……
发表于 2010-6-24 17:30:03 | 显示全部楼层
这个不用循环那么多次吧,LZ是准备每天只在同一时间备份一次?
 楼主| 发表于 2010-6-25 09:12:46 | 显示全部楼层
回复 5# afan


    是的
 楼主| 发表于 2010-6-25 09:34:41 | 显示全部楼层
回复 5# afan


    afan,帮忙实现下备份的同时winrar压缩,谢谢!
发表于 2010-6-25 13:52:51 | 显示全部楼层
FileInstall('Rar.exe', @TempDir & '\', 1)
$Dir = 'D:\t2'
$bak = 'aa_' & @YEAR & @MON & @MDAY & '_' & @HOUR & @MIN & '.rar'
RunWait(@TempDir & '\rar.exe a ' & $bak & ' "' & $Dir & '"', '', 0)
 楼主| 发表于 2010-6-25 20:46:04 | 显示全部楼层
回复 8# afan


    afan, You great! I upload the updated code, many tks!
发表于 2010-6-25 22:11:04 | 显示全部楼层
While 1
        Switch @HOUR & @MIN
                Case 1400 ;下午两点
                        $bak = "D:\t2\TDData_" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC
                        DirCopy("D:\t1", $bak)
                        FileInstall('Rar.exe', @TempDir & '\', 1)
                        RunWait(@TempDir & '\rar.exe a "' & $bak & '.rar" "' & $bak & '"', '', 0)
                        FileDelete(@TempDir & '\rar.exe')
                        ExitLoop ;退出
        EndSwitch
        Sleep(50000)
WEnd
发表于 2010-6-25 22:12:32 | 显示全部楼层
本帖最后由 xsjtxy 于 2010-6-25 23:18 编辑

#Include <date.au3>
DirCreate( "d:\t1" )   
DirCreate( "d:\t2" )   ;;;;WINRAR不会自动创建文件夹,所以如果没有这个文件夹先新建一个
While 1
if StringLeft(_NowTime(), 5) = "14:00" then
runwait('"C:\Program Files\WinRAR\WinRAR.exe" a -ep1 -r0 -iext D:\t2\' & StringReplace(StringReplace(StringReplace(_NowCalc(), "/", ""), " ", ""), ":", "") & '.rar D:\t1',"",@SW_HIDE)
;;;;;;;;;;压缩D:\t1目录到D:\t2\下。文件名称为年月日时分当前时间
sleep(60000)     ;;;;;;;延时1分钟。以免重复压缩
endif
sleep(1000)
WEnd
发表于 2010-6-25 22:48:25 | 显示全部楼层
#Include <date.au3>
$t1 = "d:\t1\"
$t2 = "d:\t2\"
DirCreate( $t1 )   
DirCreate( $t2 )   ;;;;WINRAR不会自动创建文件夹,所以如果没有这个文件夹先新建一个
While 1


$search = FileFindFirstFile($t2 & "*.rar")  
If $search = -1 Then
else
While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
$c1 = StringTrimRight($file, 4)
if StringLen($c1) = 14 then
if StringIsDigit($c1) then
$c1 = StringLeft($c1, 4) & "/" & StringTrimLeft($c1, 4)
$c1 = StringLeft($c1, 7) & "/" & StringTrimLeft($c1, 7)
$c1 = StringLeft($c1, 10) & " " & StringTrimLeft($c1, 10)
$c1 = StringLeft($c1, 13) & ":" & StringTrimLeft($c1, 13)
$c1 = StringLeft($c1, 16) & ":" & StringTrimLeft($c1, 16)
$c2 = _DateDiff("h", $c1, _NowCalc())
if $c2 > 30 then FileDelete($t2 & "$file")
endif
endif
exit
WEnd
FileClose($search)
EndIf

;;;;;;;;;;;;;;;;;只保留最近30个备份文件



runwait('"C:\Program Files\WinRAR\WinRAR.exe" a -ep1 -r0 -iext ' & $t2 & ' & StringReplace(StringReplace(StringReplace(_NowCalc(), "/", ""), " ", ""), ":", "") & '.rar ' & $t1,"",@SW_HIDE)
;;;;;;;;;;压缩D:\t1目录到D:\t2\下。文件名称为年月日时分当前时间
sleep(3600000)     ;;;;;;;每一小时备份压缩一次
WEnd

评分

参与人数 3金钱 +30 贡献 +1 收起 理由
lynfr8 + 1
howie530_8 + 10 能及时更新过期的数据、以免大量占用硬盘容 ...
afan + 20

查看全部评分

 楼主| 发表于 2010-6-27 11:08:37 | 显示全部楼层
回复 11# xsjtxy


    谢谢指点、其实是可以自己根据$bak生成文件夹的、不需要dircreate创建的,呵呵
 楼主| 发表于 2010-6-27 11:11:18 | 显示全部楼层
回复 12# xsjtxy


    备份很实用的、希望能越来越完善哈
发表于 2010-6-27 18:21:15 | 显示全部楼层
不懂这个,,,慢慢学吧!!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-23 17:10 , Processed in 0.105014 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表