bat脚本备份文件三份,第三天删除第一份的备份
时间: 2023-05-11 15:06:30 浏览: 290
windows下文件夹备份脚本(附详细说明)
5星 · 资源好评率100%
可以使用以下的bat脚本实现备份文件三份,第三天删除第一份的备份:
```
@echo off
setlocal
set source_folder=C:\path\to\source\folder
set backup_folder=C:\path\to\backup\folder
set backup_prefix=backup
set backup_suffix=%date:~0,4%%date:~5,2%%date:~8,2%
set max_backup_count=3
rem create backup folder if it doesn't exist
if not exist "%backup_folder%" mkdir "%backup_folder%"
rem backup files
for %%f in ("%source_folder%\*.*") do (
set backup_file=%backup_prefix%_%%~nf_%backup_suffix%%%~xf
copy "%%f" "%backup_folder%\%backup_file%"
)
rem delete oldest backup if there are too many backups
for /f "skip=%max_backup_count% delims=" %%f in ('dir /b /o:n "%backup_folder%\%backup_prefix%_*"') do (
del "%backup_folder%\%%f"
)
```
这个脚本会将源文件夹中的所有文件备份到备份文件夹中,备份文件名的格式为"backup_文件名_日期.扩展名"。如果备份文件夹中的备份文件数量超过了设定的最大备份数量,就会删除最旧的备份文件。
阅读全文