- <#*,:&cls
- @echo off
- cd /d "%~dp0"
- powershell -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~f0\" -ReadCount 0 | Out-String)))"
- pause
- exit /b
- #>
- # 间隔时间(单位:秒)
- $delay = 6 * 60 * 60
- # 备份源文件夹
- $srcdir = "d:\test\d\04"
- # 备份目标文件夹
- $dstdir = "d:\test\d\05"
-
- while ($true) {
- # 备份
- [System.IO.DirectoryInfo]$dstdir2 = [System.IO.Directory]::CreateDirectory([System.IO.Path]::Combine($dstdir, (Get-Date -Format 'yyyyMMddHHmmssfff')))
- Copy-Item -LiteralPath $srcdir -Destination $dstdir2 -Recurse -Verbose
- # 删除前10天的备份目录
- (Get-ChildItem -LiteralPath $dstdir | Where-Object { $_.PSIsContainer }) | ForEach-Object {
- $span0 = $_ | New-TimeSpan
- if ($span0.Days -ge 10) {
- $_ | Remove-Item -Recurse -Force -Verbose
- }
- }
- Start-Sleep -Seconds $delay
- }
复制代码
|