|
fangcheng79
新手上路

积分 10
发帖 4
注册 2006-10-19
状态 离线
|
『楼 主』:
[求助]文件的自动备份和删除
使用 LLM 解释/回答一下
在工作中经常遇到客户要求把文件自动备份的,这个我通常借助软件完成文件备份,一般的数据库都可以自身完成备份或者由DBA来做,所以也比较少遇到批处理的问题.
但是现在有一个项目,所有文件(除数据库)要定期备份,并且根据时间进行删除只保留约定数量(比如5份),这样的备份也好办,但是就是删除难办了.诚求高手给出全解,在下不胜感激.也许将来还会有别人用到,也是利人利己.
谢谢
In work, I often encounter customers asking to automatically back up files. Usually, I use software to complete file backups. General databases can usually perform backups by themselves or be done by DBAs, so there are relatively few batch processing issues.
But now there is a project where all files (except databases) need to be backed up regularly, and according to time, only a specified number (such as 5 copies) is retained. Such backups are easy to handle, but deletion is difficult. I sincerely ask experts to give a complete solution. I am very grateful. Maybe others will use it in the future, which is beneficial to both others and myself.
Thanks
|
|
2006-10-19 05:55 |
|
|
fangcheng79
新手上路

积分 10
发帖 4
注册 2006-10-19
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
这个和Windows注册表的自动备份很相似
This is very similar to the automatic backup of the Windows registry
|
|
2006-10-19 05:56 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
"并且根据时间进行删除只保留约定数量",根据的是什么时间?文件创建时间?文件的最后改动时间?还是距离当前时间的某几天前的?
"Also, it deletes according to time, keeping only the agreed number". Based on what time? The file creation time? The file's last modification time? Or the time a few days ago from the current time?
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-10-19 06:10 |
|
|
fangcheng79
新手上路

积分 10
发帖 4
注册 2006-10-19
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
文件创建的时间,备份文件不做修改,只是保证以后恢复使用
The time when the file was created. The backup file is not modified, just to ensure that it can be restored and used later.
|
|
2006-10-19 06:12 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
1.dir
@echo off
set strTime=2006-10-17
set "command=dir /a-d /od /t:c ^| findstr /irc:"^%%strTime%%""
for /f "tokens=3,*" %%i in ('%command%') do echo %%j
pause
若要删除只要把echo改为del就行了,如果处理多个目录可以考虑用call :标号 参数 的形式,代码比较好组织和修改.
2.wmic
wmic datafile where "InstallDate>='20061018000000.000000+480' and path='\\documents and settings\\xxx\桌面\\'" get caption
注意:如果想直接删除而不显示的话可以把后面的get captiong更改为call delete /NOINTERACTIVE,不加/NOINTERACRIVE则为交互方式,需要确认.
1. dir
@echo off
set strTime=2006-10-17
set "command=dir /a-d /od /t:c ^| findstr /irc:"^%%strTime%%""
for /f "tokens=3,*" %%i in ('%command%') do echo %%j
pause
To delete, just change echo to del. If dealing with multiple directories, you can consider using the form call :label parameter, which makes the code easier to organize and modify.
2. wmic
wmic datafile where "InstallDate>='20061018000000.000000+480' and path='\\documents and settings\\xxx\桌面\\'" get caption
Note: If you want to delete directly without displaying, you can change the subsequent get caption to call delete /NOINTERACTIVE. Without /NOINTERACTIVE, it is in interactive mode and requires confirmation.
|
|
2006-10-19 07:32 |
|
|
xyxFlysky
新手上路

积分 11
发帖 5
注册 2006-10-19
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
学习,高手真是多 ^0^
Learning, there are really many experts ^0^
|
|
2006-10-19 10:28 |
|
|
fangcheng79
新手上路

积分 10
发帖 4
注册 2006-10-19
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
可能是我表述的有问题,这里显示时间不能写死啊,我只动态的保证备份文件夹里规定数目的文件为最新的几个备份,假如有5个备份,当添加近来一个新的后,自动删除这5个当中最早的一个,这是一个不断翻新的过程.
和下面这个帖子相近
lilankui
新手上路
积分 6
发帖 1
注册 2006-9-5
来自 江西
状态 离线 『楼 主』: 怎样用批处理删除7天前的文件
@echo
Rem 取7天之前的日期,取回放入变量nowdate
echo wscript.echo dateadd("d",-6,date) >%tmp%\tmp.vbs
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%\tmp.vbs') do set y=%%i
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%\tmp.vbs') do set m=%%j
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%\tmp.vbs') do set d=%%k
if %m% LSS 9 set m=0%m%
if %d% LSS 9 set d=0%d%
set nowdate=%y%-%m%-%d%
我想知道for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%\tmp.vbs') do set d=%%k
这几句怎么解释,哪位高手可告诉我
『第 2 楼』:
对于日期的操作要考虑的太多了,至少用批处理是这样,回LZ 他是结合VBS脚本和批处理来完成的,代码没有测试,准备写一个关于这样的批处理,要考虑的实在是太多了,呵呵................
Last edited by fangcheng79 on 2006-10-19 at 22:03 ]
Maybe it's my expression that's problematic. Here, the time can't be hard-coded. I only dynamically ensure that the specified number of files in the backup folder are the most recent backups. For example, if there are 5 backups, when a new one is added recently, the earliest one among these 5 is automatically deleted. It's a process of constantly updating.
And it's similar to the following post
lilankui
Newcomer
Score 6
Posts 1
Registered 2006-9-5
From Jiangxi
Status Offline 『L楼 owner』: How to use batch processing to delete files older than 7 days
@echo
Rem Get the date 7 days ago, and get it into variable nowdate
echo wscript.echo dateadd("d",-6,date) >%tmp%\tmp.vbs
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%\tmp.vbs') do set y=%%i
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%\tmp.vbs') do set m=%%j
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%\tmp.vbs') do set d=%%k
if %m% LSS 9 set m=0%m%
if %d% LSS 9 set d=0%d%
set nowdate=%y%-%m%-%d%
I want to know how to interpret these lines "for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%\tmp.vbs') do set d=%%k", which expert can tell me
『2nd floor』: There are too many things to consider for date operations, at least with batch processing. Back to LZ, he combines VBS script and batch processing to complete it. The code hasn't been tested. I'm going to write a batch processing about this. There are really too many things to consider, hehe................
Last edited by fangcheng79 on 2006-10-19 at 22:03 ]
|
|
2006-10-19 21:56 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
可行的方法已经出来了,难道非要把完整代码贴出来吗?
dir /a-d /od /t:c /b可以按时间由后到前列出当前目录下的文件,把它放在for里面,用for /f "delims=" %%i in ('%command%') do set "file=%%i"
然后直接del %file%就完了.
p.s:dir还支持 dir abcd*.xxx
A feasible method has come out. Do we really have to post the complete code?
dir /a-d /od /t:c /b can list the files in the current directory from the most recent to the oldest by time. Put it inside for, use for /f "delims=" %%i in ('%command%') do set "file=%%i"
Then just del %file% is done.
p.s: dir also supports dir abcd*.xxx
|
|
2006-10-20 07:19 |
|
|
linqlou
初级用户
 
积分 32
发帖 14
注册 2006-11-22
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
我是菜鸟啊,请版主花费一点时间把完整程序贴出,谢谢
I'm a newbie. Please, moderator, spend a little time posting the complete program. Thanks
|
|
2006-11-25 13:24 |
|
|
linqlou
初级用户
 
积分 32
发帖 14
注册 2006-11-22
状态 离线
|
|
2006-11-25 23:18 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
 『第 11 楼』:
使用 LLM 解释/回答一下
@echo off
echo wscript.echo dateadd("d",-6,date)>tmp.vbs
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo tmp.vbs') do set/a a=%%i*365+%%j*12+%%k+1300
for /f "tokens=1,2,3,5* delims=- " %%a in ('dir/a-d^|findstr "199 200"') do (set/a b=%%a*365+1%%b*12+1%%c
if !b! lss %a% del "%%e")
```@echo off
echo wscript.echo dateadd("d",-6,date)>tmp.vbs
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo tmp.vbs') do set/a a=%%i*365+%%j*12+%%k+1300
for /f "tokens=1,2,3,5* delims=- " %%a in ('dir/a-d^|findstr "199 200"') do (set/a b=%%a*365+1%%b*12+1%%c
if !b! lss %a% del "%%e")
```
|

我的网络U盘 我的网络第2个U盘
论坛软件下载链接
灵雨飘零论坛
论坛新手必读,所有人的基本行为准则
刷QQ空间人气、留言的小软件 |
|
2006-11-26 03:35 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
版主超级利害~欣赏~:)))
原来 set /a a=2006*365+11*12+19+1300 …… 全把年/月/日转化成纯数字了,
然后用纯数字比对~:)
The moderator is super powerful~ Appreciate~ :)))
Originally, set /a a=2006*365+11*12+19+1300... All convert years/months/days into pure numbers,
and then compare with pure numbers~ :)))
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-11-26 06:59 |
|
|
linqlou
初级用户
 
积分 32
发帖 14
注册 2006-11-22
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
学习中......还一个问题,这个处理文件要放在哪呢,是备份文件里面还是外面,如果放里面会不会被 删掉啊
@echo off
echo wscript.echo dateadd("d",-6,date)>tmp.vbs
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo tmp.vbs') do set/a a=%%i*365+%%j*12+%%k+1300
for /f "tokens=1,2,3,5* delims=- " %%a in ('dir/a-d^|findstr "199 200"') do (set/a b=%%a*365+1%%b*12+1%%c
if !b! lss %a% del "%%e")
上述代码谁能解说一下呢
Last edited by linqlou on 2006-11-25 at 08:09 PM ]
Learning... Another question, where should this processing file be placed, inside the backup file or outside? If placed inside, will it be deleted?
@echo off
echo wscript.echo dateadd("d",-6,date)>tmp.vbs
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo tmp.vbs') do set/a a=%%i*365+%%j*12+%%k+1300
for /f "tokens=1,2,3,5* delims=- " %%a in ('dir/a-d^|findstr "199 200"') do (set/a b=%%a*365+1%%b*12+1%%c
if !b! lss %a% del "%%e")
Who can explain this code?
Last edited by linqlou on 2006-11-25 at 08:09 PM ]
|
|
2006-11-26 08:54 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
  『第 14 楼』:
使用 LLM 解释/回答一下
下面的不会删除自身:
@echo off
echo wscript.echo dateadd("d",-6,date)>tmp.vbs
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo tmp.vbs') do set/a a=%%i*366+%%j*31+%%k+3200
for /f "tokens=1,2,3,5* delims=- " %%a in ('dir/a-d^|findstr "199 200"') do (set/a b=%%a*366+1%%b*31+1%%c
if !b! lss %a% if not "%~nx0"=="%%e" del "%%e")
The following will not delete itself:
@echo off
echo wscript.echo dateadd("d",-6,date)>tmp.vbs
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo tmp.vbs') do set/a a=%%i*366+%%j*31+%%k+3200
for /f "tokens=1,2,3,5* delims=- " %%a in ('dir/a-d^|findstr "199 200"') do (set/a b=%%a*366+1%%b*31+1%%c
if !b! lss %a% if not "%~nx0"=="%%e" del "%%e")
此帖被 +13 点积分 点击查看详情 评分人:【 redtek 】 | 分数: +9 | 时间:2006-11-26 22:15 | 评分人:【 ccwan 】 | 分数: +3 | 时间:2006-11-27 02:44 | 评分人:【 chainliq 】 | 分数: -1 | 时间:2006-12-1 17:40 | 评分人:【 Dana 】 | 分数: +2 | 时间:2008-1-3 17:14 |
|
|

我的网络U盘 我的网络第2个U盘
论坛软件下载链接
灵雨飘零论坛
论坛新手必读,所有人的基本行为准则
刷QQ空间人气、留言的小软件 |
|
2006-11-26 09:33 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
版主厉害啊!等偶不受限制时定给你加分!
The moderator is awesome! When I am unrestricted, I will definitely give you extra points!
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-11-26 20:59 |
|
|