#region 服务每天备份一次数据库
///
///服务每天备份一次数据库///
public voidServiceForBackupDatabaseEveryDay()
{
Thread thread= new Thread(newThreadStart(BackupDatabaseEveryDay));
thread.IsBackground= true;
thread.Start();
}private voidBackupDatabaseEveryDay()
{while (true)
{try{//每天凌晨1点进行全备份
if (DateTime.Now.Hour == 1)
{string filename = string.Format("Grandmap.Cms_Full_{0}.bak", DateTime.Now.ToString("yyyyMMddHHmmss"));
Hashtable param= newHashtable();
param.Add("DatabaseName", "Grandmap.Cms");
param.Add("FileName", filename);//
}
Thread.Sleep(TimeSpan.FromHours(1));
}catch(Exception ex)
{
Log4Net.Error("每天凌晨1点进行全备份数据库服务异常!", ex);
}
}
}#endregion
#region 每天12点和18点进行一次差异备份
///
///每天12点和18点进行一次差异备份///
public voidServiceForBackupDatabaseWithDiffrent()
{
Thread thread= new Thread(newThreadStart(BackupDatabaseWithDiffrent));
thread.IsBackground= true;
thread.Start();
}private voidBackupDatabaseWithDiffrent()
{while (true)
{try{//每天12点和18进行差异备份
if (DateTime.Now.Hour == 12 || DateTime.Now.Hour == 18)
{string filename = string.Format("Grandmap.Cms_Diffrent_{0}.bak", DateTime.Now.ToString("yyyyMMddHHmmss"));
Hashtable param= newHashtable();
param.Add("DatabaseName", "Grandmap.Cms");
param.Add("FileName", filename);//
}
Thread.Sleep(TimeSpan.FromHours(1));
}catch(Exception ex)
{
Log4Net.Error("每天12点和18进行差异备份数据库服务异常!", ex);
}
}
}#endregion
#region 文件夹创建
///
///文件夹创建///
public voidCreateDir()
{string filedir = DateTime.Now.ToString("yyyy-MM");string xmlPath =AppDomain.CurrentDomain.BaseDirectory;
xmlPath=System.IO.Path.GetDirectoryName(xmlPath);if (!xmlPath.EndsWith("\\"))
{
xmlPath+= "\\";
}
xmlPath= string.Format("{0}DatabaseDir\\{1}", xmlPath, filedir);if (!Directory.Exists(xmlPath))
{
Directory.CreateDirectory(xmlPath);
}
}#endregion