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-11 18:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch processing automatic database backup View 1,434 Replies 14
Original Poster Posted 2007-06-17 14:05 ·  中国 四川 南充 电信
新手上路
Credits 14
Posts 7
Joined 2007-06-17 13:33
19-year member
UID 91597
Gender Male
Status Offline
d:\data is the address of the database, e:\baksql\ is the address of the backup. Students who need to use it should change it themselves!
After each backup, it is automatically named with the backup time and written to the record file!
@echo Start backup: 
@echo Backup start time: %date% %time%
@net stop mssqlserver
@net stop w3svc
@net stop iisadmin /y
@xcopy d:\data e:\baksql\ /E /h
@ren e:\baksql\Computer.mdf "%date%".mdf
@ren e:\baksql\Computer_log.LDF "%date%".LDF
@net start mssqlserver
@net start w3svc
@echo Backup completed!!
@echo End backup time: %date% %time%
@echo Backup time: %date% %time% >>e:\baksql\Backup time record.txt
@cls
@exit


If the important data can also be transferred to another FTP machine
@echo Start backup: 
@echo Backup start time: %date% %time%
@net stop mssqlserver
@net stop w3svc
@net stop iisadmin /y
@xcopy d:\data e:\baksql\ /E /h
@ren e:\baksql\Computer.mdf "%date%".mdf
@ren e:\baksql\Computer_log.LDF "%date%".LDF
@net start mssqlserver
@net start w3svc
@echo Backup completed!!
@echo End backup time: %date% %time%
@echo Backup time: %date% %time% >>e:\baksql\Backup time record.txt
@echo Uploading data to X space...
@echo ftp.exe -s:C:\jh520.mmp
@cls
@exit


Create jh520.mmp under the C root and write the following code. Some things need to be changed by yourself!


open FTPSEVER
USER
PASSWORD
#bin
cd Backup document address
lcd e:\baksql\
put "%date%".mdf
put "%date%".LDF
bye



Dear seniors, take a look. Where can it be optimized? Please give some suggestions!
Floor 2 Posted 2007-06-17 15:26 ·  中国 广东 广州 黄埔区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
Here are several questions:
1》Is there a size limit for the mdf file? Suppose there are several gigabytes of data under D:\data, can it also be written into the MDF file.
2》Can the same file be used as a backup file? Only write the changed and added ones each time, and don't generate too many files.
3》When putting it on FTP, do you need to manually enter the username and password each time? If so, can it be made into an automatic way because I want to use "Task Manager" to complete it automatically.
Floor 3 Posted 2007-06-17 16:22 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
//When putting it on the FTP, do you need to manually enter the username and password each time?

No, the username and password are placed in the jh520.mmp file.
Floor 4 Posted 2007-06-17 21:09 ·  中国 四川 南充 电信
新手上路
Credits 14
Posts 7
Joined 2007-06-17 13:33
19-year member
UID 91597
Gender Male
Status Offline
Thanks!Senior brother's suggestion. Since I need to back up this mdf which is only 30M and it's on the server, I run it only once a month through task scheduling, which is relatively stable! I have modified the following and implemented a batch script to solve all problems!

@echo Start backing up: 
@echo Backup start time: %date% %time%
@net stop mssqlserver
@net stop w3svc
@net stop iisadmin /y
@xcopy d:\data e:\baksql\ /E /h
@ren e:\baksql\Computer.mdf "%date%".mdf
@ren e:\baksql\Computer_log.LDF "%date%".LDF
@net start mssqlserver
@net start w3svc
@echo Backup completed!
@echo End backup time: %date% %time%
@echo Backup time: %date% %time% >>e:\baksql\Backup time record.txt
@echo Uploading data to X space...
(@echo open FTPSEVER
@echo USER
@echo PASSWORD
@echo #bin
@echo cd 网络备份文档地址
@echo lcd e:\baksql\
@echo put "%date%".mdf
@echo put "%date%".LDF
@echo bye)>%systemroot%\jh.exe
@echo ftp.exe -s:%systemroot%\jh.exe
@echo del %systemroot%/jh.exe
@echo@cls
@exit
Floor 5 Posted 2007-06-17 21:22 ·  中国 四川 南充 电信
新手上路
Credits 14
Posts 7
Joined 2007-06-17 13:33
19-year member
UID 91597
Gender Male
Status Offline
@echo@cls There is something wrong here!
Floor 6 Posted 2007-06-17 22:07 ·  中国 江苏 苏州 电信
新手上路
Credits 2
Posts 1
Joined 2007-05-25 20:46
19-year member
UID 89304
Gender Male
Status Offline
Learn and learn...
Floor 7 Posted 2007-06-18 14:26 ·  中国 广东 广州 黄埔区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
What program can open .mdf, .ldf files, and what code is included in jh.exe
Floor 8 Posted 2007-06-19 21:58 ·  中国 四川 南充 电信
新手上路
Credits 14
Posts 7
Joined 2007-06-17 13:33
19-year member
UID 91597
Gender Male
Status Offline
.mdf, .ldf are for MSSQL databases
jh.exe can actually be opened with Notepad, it's not a WIN32 program at all
I made it like this to prevent others from opening it!
Floor 9 Posted 2007-06-19 23:47 ·  中国 广东 广州 黄埔区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
.mdf, .ldf are for MSSQL databases.

jh.exe can actually be opened with Notepad; it's not a WIN32 program at all. I made it like this to prevent others from opening it!

Can it be converted into common formats like ZIP, RAR? I still don't understand the meaning of this sentence.

jh.exe can actually be opened with Notepad; it's not a WIN32 program at all. I made it like this to prevent others from opening it!
Floor 10 Posted 2007-06-20 18:33 ·  中国 四川 南充 电信
新手上路
Credits 14
Posts 7
Joined 2007-06-17 13:33
19-year member
UID 91597
Gender Male
Status Offline
Of course it's okay to reply to the upstairs. It's just a problem of the file extension! If you change *.txt to *.rar and then open it with Notepad, you can still see the content inside the txt.
Floor 11 Posted 2007-06-20 19:02 ·  中国 上海 电信
中级用户
★★
Credits 231
Posts 112
Joined 2007-06-19 20:44
19-year member
UID 91827
Gender Male
Status Offline
Haha, when I was a network administrator in the past, I also did this kind of thing for recording backup times. But at that time, I was only given a few minutes, and the database was too large, about 1G per month, so there was no continuous saving function named by time.

Use the method of stopping operation to stop the reading and writing of the database file?

Actually, you can use the backup tool of mssql itself~
Floor 12 Posted 2007-06-20 19:06 ·  中国 辽宁 鞍山 中移铁通
新手上路
Credits 8
Posts 3
Joined 2007-06-20 18:38
19-year member
UID 91905
Gender Male
Status Offline
Learned, thanks, expert!
Floor 13 Posted 2009-04-23 14:33 ·  中国 四川 南充 电信
新手上路
Credits 14
Posts 7
Joined 2007-06-17 13:33
19-year member
UID 91597
Gender Male
Status Offline
I've been writing batch scripts for 2 years, and the computer has been formatted N times. Fortunately, I found the old posts I posted online before!
Floor 14 Posted 2009-04-23 14:40 ·  中国 四川 南充 电信
新手上路
Credits 14
Posts 7
Joined 2007-06-17 13:33
19-year member
UID 91597
Gender Male
Status Offline
How to write with SQL Server's own backup tool?
Floor 15 Posted 2009-04-23 14:45 ·  中国 北京 联通
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
Just search for the usage of OSQL and SQLCMD.

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Forum Jump: