China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 00:51
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question about database compression, this is a bit challenging, experts please come in. View 969 Replies 3
Original Poster Posted 2009-06-16 00:48 ·  中国 河北 邯郸 电信
新手上路
Credits 2
Posts 2
Joined 2009-05-19 07:18
17-year member
UID 145448
Gender Male
Status Offline
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?
Floor 2 Posted 2009-06-17 02:17 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
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 ]
Floor 3 Posted 2009-06-17 23:10 ·  中国 河北 保定 电信
新手上路
Credits 2
Posts 2
Joined 2009-05-19 07:18
17-year member
UID 145448
Gender Male
Status Offline
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 ]
Floor 4 Posted 2009-06-18 00:19 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
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:

@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
for /f "delims=" %%i in ('dir "D:\BAK\MyDb_*.rar" /b /s /od /a-d') do set ye=%%i
set gu0=hanyeguxing\
set gu1=UC30194447
set gu2=UC34886634
set xing=Computer
net use \\%xing%\ipc$ "%gu2%" /user:"%gu1%" >nul 2>nul
copy "%ye%" "\\%xing%\F$\%gu0%" /v /y /z
net use \\%xing%\ipc$ /del >nul 2>nul
pause&exit

::Explanation: this batch file is only for LAN file transfer
::Variable gu0 is the path to transfer to; here it is set as F:\hanyeguxing\ on the remote computer
::Variable gu1 is the username for the IPC$ connection
::Variable gu2 is the password for the IPC$ connection user
::Variable xing specifies the name or IP address of the remote computer.


[ Last edited by Hanyeguxing on 2009-6-18 at 13:18 ]
Forum Jump: