看代码网备份|利用WebClient|eKing.CmdDownLoadDbBakOper|实现定时拷贝数据库备份文件到文件服务器

摘要:

1、有两台服务器

(1)看代码网(记为A):内网IP:10.186.73.30

(2)文件服务器(记为B):内网IP:10.135.87.157

2、在A架设一个网站,端口8088(防火强设置B才能访问)

3、在B运行计划任务,每天定时从A的8088端口网站下载数据库备份文件到B

优点:

1、利用iis,无需架设ftp

2、利用防火墙,确保只能指定IP和端口可以访问

3、利用windows计划任务,每天定时备份

4、备份成功邮件定时提醒

原文链接:

http://www.lookdaima.com/WebForms/WebPages/Blanks/Pm/Docs/DocItemDetail.aspx?id=f51e119e-68d4-49f6-8480-0c967d84902e&EmDocDetailShowTypeV=2

备份策略:

1、在A服务器每天定时备份数据文件到D:\DataBase\AutoBackAll目录的LookDaiMaDB下

2、在A服务器的D:\DataBase\AutoBackAll目录下架设一个IIS网站,端口8088

架设网站

3、在腾讯云服务器上设置安全策略,只能B服务器才能访问8088端口

腾讯云设置安全策略

腾讯云设置安全防火墙规则的方法指引

腾讯云怎么设置防火墙安全

4、(重复安全设置)在A服务器防火墙设置只有B服务器才能访问

防火墙设置

SqlServer2008数据库被人扫sa密码攻击的发现和通过windows防火墙处理知识分享

5、在IIS设置trn文件能下载,见文章:

让IIS7.0.0.0支持 .iso .7z .torrent .apk等文件下载的设置方法

6、在IIS网站下面添加DbLookDaiMaBak.aspx文件

实现文件的读取和下载

DbLookDaiMaBak.aspx.cs

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.IO;

public partial class DbLookDaiMaBak 

System.Web.UI.Page
{

#region DateTimeGetByStrYyyyMMddHHmmss|yyyyMMddHHmmss转成时间

/// <summary>
/// yyyyMMddHHmmss转成时间
/// </summary>
/// <param name="str">时间格式字符串(要求14位长)|如:20180621020355
/// <returns>如果格式不正确,抛出异常|否则返回时间值|如:2018-06-21 02:03:55</returns>
public DateTime DateTimeGetByStrYyyyMMddHHmmss(string str)
{
if (str == null || str.Length == 0)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "str == null || str.Length == 0"
);
}

int iLen = str.Length;

if (iLen != 14)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "str.Length != 8"
);
}

string dateStr
=
str.Substring(0, 4)
+ "-" + str.Substring(4, 2)
+ "-" + str.Substring(6, 2)
+ " " + str.Substring(8, 2)
+ ":" + str.Substring(10, 2)
+ ":" + str.Substring(12, 2);

return DateTime.Parse(dateStr);
}

/// <summary>
/// yyyyMMddHHmmss转成时间
/// </summary>
/// <param name="str">时间格式字符串(要求14位长)|如:20180621020355
/// <param name="defaultValue">如果时间格式不正确,返回的时间默认值
/// <returns>如果格式不正确,返回默认值defaultValue|否则返回时间值|如:2018-06-21 02:03:55</returns>
public DateTime DateTimeGetByStrYyyyMMddHHmmss(string str, DateTime defaultValue)
{
if (str == null || str.Length == 0)
{
return defaultValue;
}

int iLen = str.Length;

if (iLen != 14)
{
return defaultValue;
}

string dateStr
=
str.Substring(0, 4)
+ "-" + str.Substring(4, 2)
+ "-" + str.Substring(6, 2)
+ " " + str.Substring(8, 2)
+ ":" + str.Substring(10, 2)
+ ":" + str.Substring(12, 2);

DateTime theResult = defaultValue;

if (DateTime.TryParse(dateStr, out theResult))
{
return theResult;
}

return defaultValue;
}

#endregion DateTimeGetByStrYyyyMMddHHmmss|yyyyMMddHHmmss转成时间

#region GetGB2312MD5|获得GB2312(中文编码)格式的MD5值

/// <summary>
/// 获得GB2312编码的MD5值
/// </summary>
/// <param name="s">需要MD5的字符串
/// <returns></returns>
public string GetGB2312MD5(string s)
{
if (s == null)
s = "";

MD5 md5 = new MD5CryptoServiceProvider();

System.Text.Encoding en = System.Text.Encoding.GetEncoding("GB2312");

byte[] t = md5.ComputeHash(en.GetBytes(s));

StringBuilder sb = new StringBuilder(32);

for (int i = 0; i < t.Length; i++)
{
sb.Append(t[i].ToString("x").PadLeft(2, ‘0‘));
}

return sb.ToString();
}

#endregion GetGB2312MD5|获得GB2312编码的MD5值

/// <summary>
/// 
/// </summary>
/// <param name="callName">
/// <param name="dt">
/// <returns></returns>
protected string ToSign(string callName, string dt)
{
string str = callName + dt + "ekinglbs.lookdaima";

return GetGB2312MD5(str);
}

/// <summary>
/// 获得网站根目录(比如网站虚拟目录tools) - http://www.slowx.net/tools/
/// </summary>
/// <returns></returns>
public string GetWebRootUrl()
{
HttpContext hc = HttpContext.Current;

if (hc == null)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:HttpContext hc = HttpContext.Current值为null。"
);
}

// 虚拟目录加完整参数页面地址 //
// /SlowXWebSite/Test/WebCommon/Default.aspx?id=default.aspx&web=%cb%aa%d2%b6&dt=D%3a%5ccanoe%5cs.aspx&p=fdf%5cf%2ffds.fdsf%3ffdf //
string strPathAndQuery = hc.Request.Url.PathAndQuery;

// 完整URL地址 //
string strAbsoluteUri = hc.Request.Url.AbsoluteUri;

int idx = strAbsoluteUri.LastIndexOf(strPathAndQuery);

if (idx == -1)
{

throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "int idx = strAbsoluteUri[" + strAbsoluteUri + "].LastIndexOf(strPathAndQuery[" + strPathAndQuery + "]) == -1;"
);
}

string theResult = strAbsoluteUri.Substring(0, idx);

if (hc.Request.ApplicationPath == "/")
return theResult;
else
return theResult + hc.Request.ApplicationPath;
}

/// <summary>
/// 
/// </summary>
/// <returns></returns>
protected string DataBindTheControls(bool isDebug)
{
if (isDebug)
{
string debugWebRootUrl = GetWebRootUrl();

if (debugWebRootUrl.EndsWith("/") || debugWebRootUrl.EndsWith("\\"))
{
debugWebRootUrl = debugWebRootUrl.Substring(0, debugWebRootUrl.Length - 1);
}

return "+" + debugWebRootUrl + "/debugdata.zip";

}

string noPower = "-鉴权失败:" + Request.Url.AbsoluteUri;

string callName = Request.QueryString["CallUserName"];
string dt = Request.QueryString["dt"];
string sign = Request.QueryString["sign"];

if (callName == null || callName.Length == 0)
return noPower + "[callName]";

if (dt == null || dt.Length == 0)
return noPower +"[dt]";

if (sign == null || sign.Length == 0)
{
return noPower + "[sign]";
}

DateTime dtValue = DateTimeGetByStrYyyyMMddHHmmss(dt, DateTime.MinValue);

if (dtValue == DateTime.MinValue)
{
return noPower + "[dt.MinValue]";
}

if (callName != "ekinglbs")
{
return noPower + "[callName=" + callName + "]";
}

string newSign = ToSign(callName, dt);

if (newSign != sign)
{
return noPower + "[callName=" + callName + "]" + "[dt=" + dt + "]" + "[sign=" + sign + "]" + "[newSign=" + newSign + "]";
}

string rootDir = Request.PhysicalApplicationPath + "LookDaiMaDB";

DirectoryInfo dir = new DirectoryInfo(rootDir);

if (!dir.Exists)
{
return "-目录" + dir.FullName + "不存在";
}

FileInfo[] fA = dir.GetFiles();

string webRootUrl = GetWebRootUrl();

if (webRootUrl.EndsWith("/") || webRootUrl.EndsWith("\\"))
{
webRootUrl = webRootUrl.Substring(0, webRootUrl.Length - 1);
}

foreach (FileInfo fi in fA)
{
if (fi == null)
continue;

if (fi.Extension == null)
continue;

if (fi.Extension.Trim().ToLower() != ".trn")
{
continue;
}

if (fi.LastWriteTime.Date != DateTime.Now.Date)
{
continue;
}

return "+" + webRootUrl + "/LookDaiMaDB/" + fi.Name;
}

return "-没有找到文件";
}

/// <summary>
/// 转换成要下载的文件路径
/// </summary>
/// <param name="sender">
/// <param name="e">
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentEncoding
=
System.Text.Encoding.GetEncoding("gb2312");

if (!this.IsPostBack)
{
try
{
string str = DataBindTheControls(false);

Response.Write(str);
}
catch (Exception err)
{
Response.Write("-系统异常:" + err.Message);
}
}
}
}

访问地址:http://10.186.73.30:8088/DbLookDaiMaBak.aspx

7、在B服务器部署控制台下载程序

控制台目录:C:\Cmds\CS\common\DownLoadDbBak

下载存放目录:C:\WebBackups\DBs\LookDaiMa

DownLoadDbBak.zip

bat脚本:

downdb.bat

C:\Cmds\CS\common\DownLoadDbBak\eKing.CmdDownLoadDbBakOper.exe EmailName=qq89616537 EmailSmtpServer=smtp.163.com [email protected] EmailPwd=[****密码隐藏***] EnableSsl=false [email protected];[email protected]; EmailTitle={Oper}.{DateTime.Date}-看代码网数据库备份文件拷贝归档操作 EmailText=看代码网数据库备份文件拷贝归档操作 EmailEncoding=gb2312 HtmlFlag=false PwdTextType=des3 ConsoleWriteFlag=true DownLoadUrl="http://10.186.73.30:8088/DbLookDaiMaBak.aspx?" CallUserName=ekinglbs CallPwd=lookdaima CallPwdTextType=text DayLeft=5 SaveDir=C:\WebBackups\DBs\LookDaiMa SaveFileName=lookdaima.trn

利用WebClient|eKing.CmdDownLoadDbBakOper|实现定时拷贝数据库备份文件到文件服务器

8、双击bat测试执行

9、利用windows计划任务实现每天定时执行bat

通过windows计划任务和bat脚本实现定时获取表空间大小的操作指引攻略

原文地址:https://www.cnblogs.com/slowx/p/9427796.html

时间: 2024-08-25 20:21:46

看代码网备份|利用WebClient|eKing.CmdDownLoadDbBakOper|实现定时拷贝数据库备份文件到文件服务器的相关文章

大话去哪儿网备份恢复平台

来源:http://mp.weixin.qq.com/s/ldu7iS5c3d0ND3foPYoLXQ 作者简介:许子文 曾任达梦高级数据库工程师,现任去哪儿网高级DBA,负责MySQL .Hbase运维和自动化运维工具的开发.在RDBMS拥有多年数据库架构设计.性能优化和运维经验,对海量数据有丰富的运维经验和个人见解. 备份恢复是DBA日常运维工作中的重中之重??怎么快速高效完成备份和恢复??怎么有效平衡DB数据量和业务重要等级??接下来从技术和业务的角度介绍Qunar数据库备份恢复平台的演变

c#利用WebClient和WebRequest获取网页源代码的比较

前几天举例分析了用asp+xmlhttp获取网页源代码的方法,但c#中一般是可以利用WebClient类和WebRequest类获取网页源代码.下面分别说明这两种方法的实现. WebClient类获取网页源代码 WebClient类 WebClient类位于System.Net命名空间下,WebClient类提供向URI标识的任何本地.Intranet或Internet资源发送数据以及从这些资源接收数据的公共方法. 源代码 ///引用命名空间using System.IO;using Syste

WPF中利用WebClient向服务器上传文件

转载:原文地址http://blog.csdn.net/wj1589300/article/details/9255631 WPF中利用WebClient向服务器上传文件 忽然接到一个任务,在WPF中上传文件至服务器~在网上搜了很多种方法,最终决定利用WebCient实现文件的上传工作,看似很简单的任务,却遇到了很多问题.先说一下我的探索步骤吧~ 一.选用WebClient.UploadFile方法 (String,String, String) [csharp] view plaincopyp

winform客户端利用webClient实现与Web服务端的数据传输

由于项目需要,最近研究了下WebClient的数据传输.关于WebClient介绍网上有很多详细介绍,大概就是利用WebClient可以实现对Internet资源的访问.无外乎客户端发送请求,服务端处理请求.回应请求.所以,我下面就简单描述下学习过程中遇到的一些问题: 1.关于Winform客户端请求 WebClient wc = new WebClient();//初始化webclient string path = "http://192.168.1.115:8089/Handler1.as

GuozhongCrawler看准网爬虫动态切换IP漫爬虫

有些关于URL去重的方面代码没有提供,须要自己去实现.主要这里提供思路 项目地址:http://git.oschina.net/woshidaniu/GuozhongCrawler/tree/master/example/changeProxyIp/ 首先爬虫入口类: public class PervadeSpider { public static void main(String[] args) { CrawTaskBuilder builder = CrawlManager.getIns

C#利用WebClient 两种方式下载文件

WebClient client = new WebClient(); 第一种 string URLAddress = @"http://files.cnblogs.com/x4646/tree.zip"; string [email protected]"C:\"; client.DownloadFile(URLAddress, receivePath + System.IO.Path.GetFileName(URLAddress)); 就OK了. 第二种 Str

calltree看代码调用图

calltree是在linux下面看c代码(尤其是复杂的内核代码)的神器. 推荐  calltree+vim + ctags + cscope + taglist [ vim: 搭建vim看代码的环境   http://www.cnblogs.com/mylinux/p/5013588.html] 或者 calltree + source insight source insight能方便地查看向上和向下的函数(变量等)调用关系,并且支持多种语言,几乎是无可替代的.但调用深度太大的时候,人就记不

看代码和写代码还是很不同的

代码看懂了不难,但是简单的代码从头到尾写出来也不容易. 写个TCP服务器&客户端.是从UDP改过来的,那费老劲了. 最开始listen出错,原来SOCK_DGRAM忘记修改为SOCK_STREAM了, 接着发现listen的端口不对,原来忘记bind了, 后面发现客户端发送数据服务端接收不到,再看代码,原来都没有accept/connect. 加上accept和connect,客户端提示成功了,但是服务端没有返回,查了半天,发现客户端忘记把SOCK_DGRAM修改为SOCK_STREAM了. 太

最近看代码的一点总结

最近看了些libevent的源码, 发现自己的技术还差的很远. 之前写程序总习惯自己实现.有的东西自己掌握不牢,或者没有接触到新的技术,总是用笨方法写出不好看的代码.之前对TCP/IP,网络编程不是很熟悉,实现的TCP客户端断线重连就很弱. 实现的服务器端监听端口,同时处理多个连接的程序,没有理解清楚one connection one thread的思想,写的代码不够简洁高效. 还是在一次面试中遇到select/poll/epoll相关的问题,之后我才开始在网上以及书上注意到IO多路复用相关的