簡單一點方式
每個月第一天排程複製A資料夾檔案到B資料夾
每個月底排程刪除A資料夾所有檔案
這樣你B資料夾就有每個月第一天的備份了
同上~!可以使用 robocopy or powershell 實做
PowerShell
$Now = Get-Date
#定義要刪除的天數
$Days = "0"
#定義路徑
$TargetFolder = "D:\Scan Files"
#定義副檔名
$ExtensionPDF = "*.pdf"
$ExtensionTIF = "*.tif"
$ExtensionTXT = "*.txt"
#定義要刪除的日期 (刪除今天往前Days的log)
$LastWrite = $Now.AddDays(-$Days)
$FilesPDF = Get-Childitem $TargetFolder -Include $ExtensionPDF -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}
$FilesTIF = Get-ChildItem $TargetFolder -Include $ExtensionTIF -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}
$FilesTXT = Get-ChildItem $TargetFolder -Include $ExtensionTXT -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}
Write-Host "Check PDF Extension Files"
foreach ($File in $FilesPDF)
{
if ($File -ne $NULL)
{
write-host "Deleting File $File" -ForegroundColor "DarkRed"
$File.FullName | Out-File 'd:\delete_log.txt' -Append
Remove-Item $File.FullName | Out-Null
}
else
{
Write-Host "No more files to delete!" -foregroundcolor "Green"
Start-Sleep -Seconds 5
}
}
Write-Host "Check TIFF Extension Files"
foreach ($File in $FilesTIF)
{
if ($File -ne $NULL)
{
write-host "Deleting File $File" -ForegroundColor "DarkRed"
$File.FullName | Out-File 'd:\delete_log.txt'-Append
Remove-Item $File.FullName | Out-Null
}
else
{
Write-Host "No more files to delete!" -foregroundcolor "Green"
Start-Sleep -Seconds 5
}
}
Bath for Robocopy
rem 刪除前一天備份的檔案
rd "d:\upsdata\delete_log\" /s /q
rem 移動大於兩天的檔案至 delete_log 資料夾
robocopy "D:\Scan Files" "D:\DELETE_LOG" /e /zb /maxage:2 /xf "D:\Scan Files\*.txt" /move /log:"d:\delete_log.txt"