howie530_8 发表于 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没有实现、请高手帮忙,谢谢!

afan 发表于 2010-6-24 15:48:30

围观处女贴……
不见提问字样,lZ是要分享源码吗?

howie530_8 发表于 2010-6-24 16:28:02

回复 2# afan


    恩、是的

afan 发表于 2010-6-24 16:30:20

回复 3# howie530_8


    晕~ 那你就分享啊,到时候转到源码区……

afan 发表于 2010-6-24 17:30:03

这个不用循环那么多次吧,LZ是准备每天只在同一时间备份一次?

howie530_8 发表于 2010-6-25 09:12:46

回复 5# afan


    是的

howie530_8 发表于 2010-6-25 09:34:41

回复 5# afan


    afan,帮忙实现下备份的同时winrar压缩,谢谢!

afan 发表于 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)

howie530_8 发表于 2010-6-25 20:46:04

回复 8# afan


    afan, You great! I upload the updated code, many tks!

afan 发表于 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

xsjtxy 发表于 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

xsjtxy 发表于 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

howie530_8 发表于 2010-6-27 11:08:37

回复 11# xsjtxy


    谢谢指点、其实是可以自己根据$bak生成文件夹的、不需要dircreate创建的,呵呵

howie530_8 发表于 2010-6-27 11:11:18

回复 12# xsjtxy


    备份很实用的、希望能越来越完善哈

qq512086170 发表于 2010-6-27 18:21:15

不懂这个,,,慢慢学吧!!!
页: [1]
查看完整版本: 数据在指定时间备份并压缩为系统时间命名的压缩文件