以下是本人QQ空间早期日记. 都是自己实际工作中用到的(分享一下)
第一种: 网页版.这个手动备份的.- using (SqlConnection conn = new SqlConnection(cn))
- {
- conn.Open();
- string sql1 = "DUMP TRANSACTION code WITH NO_LOG";
- string sql11 = "BACKUP LOG code WITH NO_LOG";
- string sql2 = "DUMP TRANSACTION code WITH NO_LOG";
- string sql22 = "BACKUP LOG code WITH NO_LOG";
- using (SqlCommand cmd = new SqlCommand(sql1, conn))
- {
- cmd.ExecuteNonQuery();
- }
- using (SqlCommand cmd = new SqlCommand(sql11, conn))
- {
- cmd.ExecuteNonQuery();
- }
- using (SqlCommand cmd = new SqlCommand("update zhiyuan set sb='..',linkzt='..'", conn))
- {
- cmd.ExecuteNonQuery();
- }
- using (SqlCommand cmd = new SqlCommand(sql2, conn))
- {
- cmd.ExecuteNonQuery();
- }
- using (SqlCommand cmd = new SqlCommand(sql22, conn))
- {
- cmd.ExecuteNonQuery();
- }
- }
- try
- {
- if (File.Exists(Server.MapPath("xx.rar")))
- {
- File.Delete(Server.MapPath("xx.rar"));
- }
- // System.IO.StreamWriter s = new StreamWriter((System.IO.Stream)File.OpenWrite(MapPath("link.rar")));
- }
- catch (Exception ex)
- { }
- SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
- SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
- try
- {
- oSQLServer.LoginSecure = false;
- oSQLServer.Connect("IP", "sa", "密码");
- oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
- oBackup.Database = "数据库";
- oBackup.Files = "[" + MapPath("xx.rar") + "]";
- oBackup.BackupSetName = "xx";
- oBackup.BackupSetDescription = "数据库备份";
- oBackup.Initialize = true;
- oBackup.SQLBackup(oSQLServer);
- ClientScript.RegisterStartupScript(this.GetType(), "m2", "<script>alert('备份成功')</script>");
- }
- catch (Exception exx)
- {
- ClientScript.RegisterStartupScript(this.GetType(), "m2", "<script>alert('备份失败')</script>");
- }
复制代码 第二种:服务器版 在sql server 代理中.作业里- DUMP TRANSACTION link WITH NO_LOG
- BACKUP LOG link WITH NO_LOG
- DECLARE @Num varchar(50)
- SET @Num = 'D:\bak\'+ convert(varchar(50),getdate(),5)+'.bak'
- backup database link to disk=@Num with format
复制代码 |