中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-12 02:26
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Question about database compression, this is a bit challenging, experts please come in.
Printable Version  971 / 3
Floor1 zmrmyll Posted 2009-06-16 00:48
新手上路 Posts 2 Credits 2
Use SQL to automatically back up the database, generating it in the D:\BAK\ directory. The generated filename is MyDb_20090615 full backup.BAK .

Now I want to compress the database, and delete the original file.

The problem is that the automatically backed-up database name changes every day. Today it is MyDb_20090615 full backup.BAK, tomorrow it will be MyDb_20090616 full backup.BAK.

How can I make RAR identify it automatically, and then compress that database?
Floor2 Hanyeguxing Posted 2009-06-17 02:17
银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂
cmd /c "C:\Program Files\WinRAR\WinRAR.exe" m -ag -cfg- -ibck -inul -m5 -s -y "D:\BAK\MyDb_" "D:\BAK\MyDb_%date:~0,4%%date:~5,2%%date:~8,2%完全备份.BAK"

If you think the command above is too long, you can use a batch file:

@echo off
set han=D:\BAK\MyDb_%date:~0,4%%date:~5,2%%date:~8,2%
"C:\Program Files\WinRAR\WinRAR.exe" m -afrar -cfg- -ibck -inul -m5 -or -s -y %han% %han%完全备份.BAK
pause&exit


Explanation:
Example of the %date% variable: 2009-06-17 Wednesday


Explanation of WinRAR command switches:
Command M - move files and folders to the archive (that is, delete the original source/target files after compressing)
Switch -AG - generate the archive filename using the current date and time
Switch -AF<type> - specify the archive format
Switch -CFG- - ignore default settings and environment variables
Switch -DR - clear files after archiving. Before deleting the files, overwrite the file data with 0 bytes to prevent the files from being recovered.
Switch -IBCK - run WinRAR in the background
Switch -INUL - disable error messages
Switch -IOFF - shut down PC power
Switch -M<n> - set compression method
Switch -OR - automatically rename extracted files if a file with the same name already exists.
Switch -S - create solid archive
Switch -Y - assume the answer to all prompts is “yes”
Switch -TA<date> - only process files modified after the specified date
Switch -TB<date> - process files modified before the specified date
Switch -TN<time> - process files newer than the specified time
Switch -TO<time> - process files older than the specified time


OP, pay attention to post format and the topic title, so that after I reply it doesn't always get deleted. . .

[ Last edited by Hanyeguxing on 2009-6-17 at 02:39 ]
Floor3 zmrmyll Posted 2009-06-17 23:10
新手上路 Posts 2 Credits 2
Thanks, the test succeeded! But there's still another problem: I want to transfer the newest backed-up file to another machine for offsite backup. How can I do that? Automatically... There are several backed-up databases in this directory, so how can it tell which one is the newest?

[ Last edited by zmrmyll on 2009-6-17 at 23:25 ]
Floor4 Hanyeguxing Posted 2009-06-18 00:19
银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂
Using the batch file above as an example, the generated backup archive name is D:\BAK\MyDb_20090617.rar, and that should be the newest one. If multiple backup archives are made in one day, then you can use:



[ Last edited by Hanyeguxing on 2009-6-18 at 13:18 ]
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023