如何实现在asp中备份、还原、压缩sql数据库?再线等!

opdesign 2004-04-06 02:30:57
如何实现在asp中备份、还原、压缩sql数据库?再线等!
...全文
78 点赞 收藏 11
写回复
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
19az 2004-08-02
感谢crazyboy119(刀剑笑)提供的程序,不过在错误检测方面好像不是太好
回复
swich 2004-04-26
来接分的
回复
loveweb 2004-04-26
你想怎么做?
看下联机帮助
把那些命令写在SQL语句再调用就行啦
回复
fenlin 2004-04-26
海蛙同志的代码就可以啊!
您要怎么样备份?
回复
bluesky1314520 2004-04-26
crazyboy119(刀剑笑)的回答不是对的嘛,照着这个做就行了,这个代码肯定没有问题的
回复
opdesign 2004-04-26
这么久了!这个问题依旧没有回答到位!!难道我要将问题带到棺材里去吗!!!我自己顶一下!!1大家高抬贵手!!!帮个小忙!!!
回复
crazyboy119 2004-04-06
<HTML>
<HEAD>
<TITLE>SQL Server 数据库的备份与恢复</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<BODY topmargin="30">
<form method="post" name=myform>
 
<label for=act_restore></label>
<br>
<br>
<table width="85%" border="1" align="center" style="border-collapse:collapse" cellpadding="3" cellspacing="0" bordercolor="#000000">
<tr>
<td colspan="2" bgcolor="#CCCCCC"> <div align="center">
<label for=act_backup>数据库管理</label>
</div></td>
</tr>
<tr>
<td width="19%">选择操作:
<label for=label></label> </td>
<td width="81%"> <input type="radio" name="act" id="radio2" value="backup" checked>
<label for=act_backup>备份</label>   
<input type="radio" name="act" id="radio3" value="restore">
<label for=act_restore>恢复</label>
<font color="red">(注意:恢复时请在没有使用数据库时进行!)</font></td>
</tr>
<tr>
<td>数据库名:</td>
<td><input type="text" name="databasename" value="<%=request("databasename")%>"></td>
</tr>
<tr>
<td>文件路径:</td>
<td><input type="text" name="bak_file" value="c:\$1.bak">
(备份或恢复的文件路径)</td>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="2">
<div align="center">
<input name="submit" type="submit" value="确定">
</div></td>
</tr>
</table>
</form>
<%
'SQL Server 数据库的备份与恢复!
dim sqlserver,sqlname,sqlpassword,sqlLoginTimeout,databasename,bak_file,act
sqlserver = "localhost" 'sql服务器
sqlname = "sa" '用户名
sqlpassword = "" '密码
sqlLoginTimeout = 15 '登陆超时
databasename = trim(request("databasename"))
bak_file = trim(request("bak_file"))
bak_file = replace(bak_file,"$1",databasename)
act = lcase(request("act"))
if databasename = "" then
response.Write "please input the database!"
else
if act = "backup" then
Set srv=Server.CreateObject("SQLDMO.SQLServer")
srv.LoginTimeout = sqlLoginTimeout
srv.Connect sqlserver,sqlname, sqlpassword
Set bak = Server.CreateObject("SQLDMO.Backup")
bak.Database=databasename
bak.Devices=Files
bak.Files=bak_file
bak.SQLBackup srv
if err.number>0 then
response.write err.number&"<font color=red><br>"
response.write err.description&"</font>"
end if
Response.write "<center><font color=red size=5>备份成功!</font></center>"
elseif act = "restore" then
'恢复时要在没有使用数据库时进行!
Set srv=Server.CreateObject("SQLDMO.SQLServer")
srv.LoginTimeout = sqlLoginTimeout
srv.Connect sqlserver,sqlname, sqlpassword
Set rest=Server.CreateObject("SQLDMO.Restore")
rest.Action=0 ' full db restore
rest.Database=databasename
rest.Devices=Files
rest.Files=bak_file
rest.ReplaceDatabase=True 'Force restore over existing database
if err.number>0 then
response.write err.number&"<font color=red><br>"
response.write err.description&"</font>"
end if
rest.SQLRestore srv

Response.write "<font color=green>恢复成功!</font>"
else
Response.write "<font color=red>没有选择操作</font>"
end if
end if
%>
<br>
</BODY>
</HTML>
回复
cheqiang 2004-04-06
也可以调用SQLServer管理组件!

网上很多参考代码
回复
51windows 2004-04-06
http://www.csdn.net/Develop/read_article.asp?id=26262
回复
sdliubo 2004-04-06
sql联机帮助都有 自己查一下
回复
sdliubo 2004-04-06
BACKUP
备份整个数据库、事务日志,或者备份一个或多个文件或文件组。有关数据库备份和恢复操作的更多信息,请参见备份和还原数据库。

语法
备份整个数据库:

BACKUP DATABASE { database_name | @database_name_var }
TO < backup_device > [ ,...n ]
[ WITH
[ BLOCKSIZE = { blocksize | @blocksize_variable } ]
[ [ , ] DESCRIPTION = { 'text' | @text_variable } ]
[ [ , ] DIFFERENTIAL ]
[ [ , ] EXPIREDATE = { date | @date_var }
| RETAINDAYS = { days | @days_var } ]
[ [ , ] PASSWORD = { password | @password_variable } ]
[ [ , ] FORMAT | NOFORMAT ]
[ [ , ] { INIT | NOINIT } ]
[ [ , ] MEDIADESCRIPTION = { 'text' | @text_variable } ]
[ [ , ] MEDIANAME = { media_name | @media_name_variable } ]
[ [ , ] MEDIAPASSWORD = { mediapassword | @mediapassword_variable } ]
[ [ , ] NAME = { backup_set_name | @backup_set_name_var } ]
[ [ , ] { NOSKIP | SKIP } ]
[ [ , ] { NOREWIND | REWIND } ]
[ [ , ] { NOUNLOAD | UNLOAD } ]
[ [ , ] RESTART ]
[ [ , ] STATS [ = percentage ] ]
]

回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告