日期:2014-05-18 浏览次数:20417 次
恢复数据库: 关键字:Alter Database 被恢复的数据库名 Set Offline with Rollback immediate; restore database 被恢复的数据库名 from disk = '备份文件路径'; Alter Database 被恢复的数据库名 Set OnLine With rollback Immediate; ///////////////////// string sql = "Alter Database db Set Offline with Rollback immediate;"; //db 是要备份的数据库名 sql += "restore database db from disk = '" ; sql += Server.MapPath("").ToString() +"\\"; sql += bakname + "'"; //bakname 是备份文件名 sql += "Alter Database db Set OnLine With rollback Immediate;"; try { 连接 master 数据库 ; 执行 sql 语句; Response.Write("<script language=javascript>alert('数据恢复成功!');</script>"); } catch(Exception ex) { Response.Write("<script language=javascript>alert('数据恢复失败!');</script>"); this.Label2.Text = ex.ToString(); } 备份数据库: 关键字:backup database 被备份的数据库名 to disk ='备份文件路径'; ////////////////////// string sql = "backup database db to disk = '" + Server.MapPath("").ToString() +"\\" + bakname //备份文件名 + System.DateTime.Now.DayOfYear.ToString() + System.DateTime.Now.Millisecond.ToString() + ".bak'"; Database data = new Database(); data.oper_data(sql); Response.Write("<script language=javascript>alert('备份成功!');location='restore.aspx'</script>");
------解决方案--------------------
备份数据库感觉是就是写sql语句,在执行就ok了. 顶楼上
------解决方案--------------------
第一种方式
-- Start 备份数据
DECLARE @dateString nvarchar(255);
SET @dateString = N'D:\Web\DB_back\cpgz_UniProfile\cpgz_UniProfile_' + CONVERT(varchar,DATEADD(Day,0,GETDATE()),112) + '.bak'
BACKUP DATABASE cpgz_UniProfile
TO DISK = @dateString WITH NOFORMAT, INIT, NAME = N'ODS_Central-完整 数据库 备份', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
-- end 备份数据
-- Start 删除3天前的备份文件
declare @d Nvarchar(256);
set @d ='del D:\Web\DB_back\cpgz_UniProfile\cpgz_UniProfile_' + convert(varchar,dateadd(day,-3,getdate()),112) + '.bak';
exec master..xp_cmdshell @d
-- end
第二种方试
-- Start 自动备份:
declare @time nvarchar(100)
declare @RuJing nvarchar(100)
set @time=CONVERT(varchar(100), GETDATE(), 112)
set @RuJing='D:\Web\DB_back\cpgz_UniProfile\cpgz_UniProfile_'+@time+'.bak'
Backup database cpgz_UniProfile to
disk=@RuJing
-- end 自动备份