php数据库备份和还原,数据库备份和还原

1.备份 if (DirectoryExists(EdtLJ.Text))=false then // EdtLJ.Text备份绝对路径 begin ForceDirectories(EdtLJ.Text); end; strsql:=' backup database Demo to disk=' ; strsql:=strsql+#39+EdtLJ.Text+'/'+EdtMC.text+#39; //EdtMC.text备份文件名称 Dia

1.备份

if (DirectoryExists(EdtLJ.Text))=false then // EdtLJ.Text备份绝对路径

begin

ForceDirectories(EdtLJ.Text);

end;

strsql:=' backup database Demo to disk=' ;

strsql:=strsql+#39+EdtLJ.Text+'/'+EdtMC.text+#39; //EdtMC.text备份文件名称

Dialogs.ShowMessage(strsql);

with adoquery2 do

begin

close;

sql.Text:=strsql;

execSql;

showmessage('备份成功!');

end;

或者

//开始备份

with adoquery1 do

begin

close;

sql.Clear;

sql.Add('Backup database library to disk=:p1 with init');

parameters.ParamByName('p1').Value:=self.SaveDialog1.FileName;

try

Execsql;

ShowMessage('备份成功!!');

except

ShowMessage('备份失败!!');

exit;

end;

end; //End of 备份

2.还原

方法1

use master --这样避免正在使用要还原的库

go

declare cur cursor for

select spid from sysprocesses where dbid=db_id('Demo')

open cur

declare @spid int

declare @str varchar(100)

fetch next from cur into @spid

while @@fetch_status=0

begin

set @str=ltrim(@spid)

exec ('kill '+@str)

fetch next from cur into @spid

end

close cur

deallocate cur

go

restore database Demo from disk='d:/111.bak' with replace

方法2

alter database Demo set offline with rollback immediate

restore database Demo from disk='E:/1.bak' //还原语句

alter database Demo set online with rollback immediate

以上程序仅供参考,有什么不对的地方还请多多指教!

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值