基本信息
源码名称:C# 定时备份数据库工具源码下载
源码大小:0.19M
文件格式:.rar
开发语言:C#
更新时间:2016-03-27
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using BackupFileConfig;
using System.IO;
namespace BackupFileService
{
public partial class BakService : ServiceBase
{
private System.Timers.Timer _timer;
public BakService()
{
_timer = new System.Timers.Timer(60000);
_timer.Enabled = false;
InitializeComponent();
_timer.Elapsed = new System.Timers.ElapsedEventHandler(_timer_Elapsed);
}
void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (e.SignalTime.Hour == ConfigLoader.Instance.ParameterConfig.ExcuteTime.Hour && e.SignalTime.Minute == ConfigLoader.Instance.ParameterConfig.ExcuteTime.Minute)
{
if (Connect.connect(ConfigLoader.Instance.ParameterConfig.FileServerIp.ToString(), ConfigLoader.Instance.ParameterConfig.UserName.ToString(), ConfigLoader.Instance.ParameterConfig.Pwd.ToString()))
{
//备份文件
BackupFile(ConfigLoader.Instance.ParameterConfig.FileSource, ConfigLoader.Instance.ParameterConfig.FileBackupPath);
//执行bat导出数据库
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "backupDb.bat");
ExcuteProcess.ExecuteCommand(path, "", ConfigLoader.Instance.ParameterConfig.DbUserName, ConfigLoader.Instance.ParameterConfig.DbPwd, ConfigLoader.Instance.ParameterConfig.DbServerName, ConfigLoader.Instance.ParameterConfig.DbBackupPath);
}
else
{
//没有共享的情况
}
}
}
protected override void OnStart(string[] args)
{
_timer.Start();
}
protected override void OnStop()
{
_timer.Stop();
}
/// <summary>
/// 备份文件
/// </summary>
/// <param name="source">文件源路径</param>
/// <param name="backupPath">文件备份路径</param>
private void BackupFile(string source, string backupPath)
{
//判断源路径是否存在
if (!Directory.Exists(source))
{
return;
}
//判断目标路径是否存在
if (!Directory.Exists(backupPath))
{
Directory.CreateDirectory(backupPath);
}
//进行copy操作
CopyDirectoryHelper _Info = new CopyDirectoryHelper(source, backupPath);
_Info.StarCopy();
}
}
}