|
rocketer
新手上路

积分 18
发帖 8
注册 2006-12-1
状态 离线
|
『楼 主』:
请问如何在批处理文件中引入系统日期作为生成的文件名?
使用 LLM 解释/回答一下
请问如何在批处理文件中引入系统日期作为生成的文件名?
本人每天做数据库MySQL的备份,打dos命令:
mysqldump -uroot -proot -B qyzx > c:\qyzx_mysql.sql
然后手工改文件名为带当天日期的文件名,如:qyzx_mysql_20061128.sql
请问怎么在批处理文件名中取系统当天日期自动加入到命令中呢?
进一步,有没有取昨天,前天,明天后天等相对日期运算的办法呢?
另外批处理命令属于什么语法?要看什么类型的书呢?想学学。
本人初学者,几乎不会写批处理,只会把Dos命令简单填入bat文件中。
请高手指教,谢谢!~~~~~~~~~~
How to introduce the system date as the generated file name in a batch file?
I back up the MySQL database every day, typing the DOS command:
mysqldump -uroot -proot -B qyzx > c:\qyzx_mysql.sql
Then manually change the file name to a file name with the current date, such as: qyzx_mysql_20061128.sql
How to get the current system date in the batch file name and automatically add it to the command?
Further, is there a way to perform relative date calculations like getting yesterday, the day before yesterday, tomorrow, the day after tomorrow, etc.?
In addition, what syntax does the batch processing command belong to? What type of book should I read? I want to learn.
I am a beginner, I can hardly write batch processing, I can only simply fill the Dos command into the bat file.
Please give instructions from the experts, thank you! ~~~~~~~~~~
|
|
2006-12-1 00:48 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
mysqldump -uroot -proot -B qyzx > c:\qyzx_mysql_%date::=-%.sql
mysqldump -uroot -proot -B qyzx > c:\qyzx_mysql_%date::=-%.sql
|
|
2006-12-1 02:30 |
|
|
rocketer
新手上路

积分 18
发帖 8
注册 2006-12-1
状态 离线
|
『第 3 楼』:
谢谢,但是没成功,似乎哪个地方........
使用 LLM 解释/回答一下
谢谢,但是没成功,似乎哪个地方........
Microsoft Windows 2000 [Version 5.00.2195]
(C) 版权所有 1985-2000 Microsoft Corp.
D:\>mysqldump -uroot -proot -B qyzx > c:\qyzx_mysql_%date::=-%.sql
mysqldump: Got error: 1102: Incorrect database name '2006-11-30.sql' when select
ing the database
D:\>myrun1
D:\>mysqldump -uroot -proot -B qyzx 2006-11-30.sql 1>c:\qyzx_mysql_星期四
mysqldump: Got error: 1102: Incorrect database name '2006-11-30.sql' when select
ing the database
D:\>
Thanks, but it didn't succeed. It seems there's something wrong somewhere........
Microsoft Windows 2000
(C) Copyright 1985-2000 Microsoft Corp.
D:\>mysqldump -uroot -proot -B qyzx > c:\qyzx_mysql_%date::=-%.sql
mysqldump: Got error: 1102: Incorrect database name '2006-11-30.sql' when select
ing the database
D:\>myrun1
D:\>mysqldump -uroot -proot -B qyzx 2006-11-30.sql 1>c:\qyzx_mysql_星期四
mysqldump: Got error: 1102: Incorrect database name '2006-11-30.sql' when select
ing the database
D:\>
|
|
2006-12-1 04:03 |
|
|
rocketer
新手上路

积分 18
发帖 8
注册 2006-12-1
状态 离线
|
『第 4 楼』:
??
使用 LLM 解释/回答一下
生成的文件是
qyzx_mysql_星期四
没有扩展名
The generated file is qyzx_mysql_Thursday with no extension.
|
|
2006-12-1 04:05 |
|
|
rocketer
新手上路

积分 18
发帖 8
注册 2006-12-1
状态 离线
|
『第 5 楼』:
谢谢
使用 LLM 解释/回答一下
我加了个双引号,改为
mysqldump -uroot -proot -B qyzx > "c:\qyzx_mysql_%date::=-%.sql"
得到的备份文件名为:
qyzx_mysql_星期四 2006-11-30.sql
基本可以了,谢谢!!!但有没有更好一点的,
把汉字星期四和后面的空格甚至日期之间的横线去掉的写法呢?
也就是按照20061130的日期格式呢?谢谢
因为想生成的文件名标准一点,可以直接在命令行上敲,
文件名有汉字和空格就不太好了,谢谢
Last edited by rocketer on 2006-11-30 at 04:34 PM ]
I added a pair of double quotes and changed it to
mysqldump -uroot -proot -B qyzx > "c:\qyzx_mysql_%date::=-%.sql"
The obtained backup file name is:
qyzx_mysql_Thursday 2006-11-30.sql
It's basically okay, thank you!!! But is there a better way,
Remove the Chinese character "Thursday" and the subsequent spaces and even the horizontal lines between the dates?
That is, according to the date format of 20061130? Thank you
Because I want the generated file name to be more standard, which can be directly typed on the command line,
File names with Chinese characters and spaces are not very good, thank you
Last edited by rocketer on 2006-11-30 at 04:34 PM ]
|
|
2006-12-1 04:10 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
for /f "tokens=1-4 delims=:-" %%i in ("%date:~0,10%") do set DT=%%i%%j%%k
set DT=%DT: =0%
mysqldump -uroot -proot -B qyzx > c:\qyzx_mysql_%DT%.sql
```
for /f "tokens=1-4 delims=:-" %%i in ("%date:~0,10%") do set DT=%%i%%j%%k
set DT=%DT: =0%
mysqldump -uroot -proot -B qyzx > c:\qyzx_mysql_%DT%.sql
```
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-1 04:29 |
|
|
rocketer
新手上路

积分 18
发帖 8
注册 2006-12-1
状态 离线
|
『第 7 楼』:
谢谢!
使用 LLM 解释/回答一下
但我试了一下,结果是
qyzx_mysql_星期四020061.sql
似乎是差在哪个小小的地方???
还请高手继续帮我看看???
可以把 mysqldump -uroot -proot -B qyzx
换成个 dir
看看生成的文件名是否是希望的,谢谢,
我可是看不懂了,慢慢学
But I tried it, and the result is
qyzx_mysql_星期四020061.sql
It seems to be a small place that's different? ? ?
Please let the expert continue to take a look? ? ?
You can replace mysqldump -uroot -proot -B qyzx
with a dir
to see if the generated file name is what is expected, thank you,
I really don't understand, learning slowly
|
|
2006-12-1 05:20 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
不好意思,我们的时间格式不一样,("%date:~0,10%") 改为("%date:~0,13%") 再试试
I'm sorry, our time formats are different. Change ("%date:~0,10%") to ("%date:~0,13%") and try again
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-1 06:01 |
|
|
rocketer
新手上路

积分 18
发帖 8
注册 2006-12-1
状态 离线
|
『第 9 楼』:
谢谢!
使用 LLM 解释/回答一下
这次是
qyzx_mysql_星期四02006113.sql
要是星期四后面那个零跑到最后就对了,
哦?原来还有不同时间格式的问题啊?我如何知道时间格式呢?
最终弄好后换台机器运行还有乱的可能么?
另外汉字是消不掉的咯?????
谢谢
This time it's
qyzx_mysql_Thursday02006113.sql
If the zero after Thursday runs to the end, it will be correct.
Oh? So there are problems with different time formats? How do I know the time format?
Is there still a possibility of chaos when running on another machine after finally getting it right?
Also, the Chinese characters can't be eliminated??????
Thanks
|
|
2006-12-1 06:55 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
win2000测试通过:
for /f "tokens=1-4 delims=:-" %%i in ("%date:~0,14%") do set DT=%%i%%j%%k%%l
set DT=%DT: =%
mysqldump -uroot -proot -B qyzx > qyzx_mysql_%DT%.sql
Win2000 test passed:
for /f "tokens=1-4 delims=:-" %%i in ("%date:~0,14%") do set DT=%%i%%j%%k%%l
set DT=%DT: =%
mysqldump -uroot -proot -B qyzx > qyzx_mysql_%DT%.sql
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-1 07:07 |
|
|
rocketer
新手上路

积分 18
发帖 8
注册 2006-12-1
状态 离线
|
『第 11 楼』:
谢谢!!!
使用 LLM 解释/回答一下
成功了
qyzx_mysql_星期四20061130.sql
谢谢您!!!
那个星期看来是消掉比较麻烦了,不过现在已经很不错了,再次感谢!!!
现在看不明白,慢慢学吧。
It worked.
qyzx_mysql_Thursday20061130.sql
Thank you!!!
That week seems relatively difficult to eliminate, but it's already very good now. Thanks again!!!
I don't understand it now, I'll learn it slowly.
|
|
2006-12-1 08:10 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
要去掉星期几,将代码改为:
for /f "tokens=1-4 delims=:-" %%i in ("%date:~3,14%") do set DT=%%i%%j%%k%%l
set DT=%DT: =%
mysqldump -uroot -proot -B qyzx > qyzx_mysql_%DT%.sql
你可以根据两次代码的不同,来分析如何实现,就会明白了。
To remove the day of the week, change the code to:
for /f "tokens=1-4 delims=:-" %%i in ("%date:~3,14%") do set DT=%%i%%j%%k%%l
set DT=%DT: =%
mysqldump -uroot -proot -B qyzx > qyzx_mysql_%DT%.sql
You can analyze how to achieve it according to the differences between the two codes, and then you will understand.
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-1 20:49 |
|
|
rocketer
新手上路

积分 18
发帖 8
注册 2006-12-1
状态 离线
|
『第 13 楼』:
太强了!!!
使用 LLM 解释/回答一下
太谢谢了!!!此贴我已珍藏,再次感谢!!!
Thank you so much!!! I have bookmarked this post and thank you again!!!
|
|
2006-12-2 09:55 |
|
|
tao0610
高级用户
    朦胧的世界
积分 579
发帖 218
注册 2006-10-24
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
xp sp2
set name=%date:~0,-4%
mysqldump -uroot -proot -B qyzx > qyzx_mysql_%name:-=%.sql
xp sp2
set name=%date:~0,-4%
mysqldump -uroot -proot -B qyzx > qyzx_mysql_%name:-=%.sql
|

认识自己,降伏自己,改变自己,才能改变别人! |
|
2006-12-3 03:54 |
|
|
aheng
新手上路

积分 4
发帖 2
注册 2006-12-6
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
配合一个软件可以实现 我这里有 要的加我QQ 403188070 我发给你
Can be implemented with a software. I have it here. If you need it, add my QQ 403188070 and I'll send it to you
|
|
2006-12-6 06:32 |
|