修改发布程序

Test.EIImageViewer
hang 2023-05-05 11:24:39 +08:00
parent 7de5056715
commit bdf841ad4b
5 changed files with 88 additions and 10 deletions

View File

@ -247,15 +247,89 @@ namespace PublishSite
}
else
{
using (var client = new SshClient(Host, UserName, Password))
{
var backRootPath = jObjectCofig[]
// 连接到远程服务器
client.Connect();
// 判断文件夹是否存在
var backupFolderPath = "/path/to/backup/folder";
var command = $"if [ ! -d '{backupFolderPath}' ]; then mkdir {backupFolderPath}; fi";
var result = client.RunCommand(command);
try
{
var dbName = bakDbName.Text.Trim();
var backRootPath = backPathTBox.Text.Trim();
var serviceName = jObjectCofig["DefaultService"]["ServiceName"].ToString().Trim();
var programFolder = backPublishPath.Text.Trim();
var dbUser = jObjectCofig["BackUp"]["DBUser"].ToString().Trim();
var dbPwd = jObjectCofig["BackUp"]["DBPwd"].ToString().Trim();
var backupFolderPath = Path.Combine(backRootPath, DateTime.Now.ToString("yyyyMMdd"));
//创建文件夹
WinformLog("准备当日备份文件夹...");
var command = client.CreateCommand($"if not exist \"{backupFolderPath}\" mkdir \"{backupFolderPath}\"");
command.Execute();
if (command.ExitStatus != 0)
{
throw new Exception($"Failed to create {backupFolderPath}.");
}
////停止服务
//WinformLog($"停止后台服务{serviceName}...");
//var stopServiceCommand = client.CreateCommand($"sc stop \"{serviceName}\"");
//command.Execute();
//if (command.ExitStatus != 0)
//{
// throw new Exception($"Failed to stop {serviceName}.");
//}
////备份后端文件
//WinformLog($"备份后端文件...");
//string archivePath = $"{backupFolderPath}\\NetCore.zip";
//command = client.CreateCommand($"powershell.exe Compress-Archive -Path \"{programFolder}\\*.*\" -DestinationPath \"{archivePath}\" -Force");
//command.Execute();
//if (command.ExitStatus != 0)
//{
// throw new Exception("Failed to compress and move folder contents.");
//}
////启动服务
//WinformLog($"停止后台服务{serviceName}...");
//var startServiceCommand = client.CreateCommand($"sc start \"{serviceName}\"");
//command.Execute();
//if (command.ExitStatus != 0)
//{
// throw new Exception($"Failed to start {serviceName}.");
//}
//备份数据库
WinformLog($"开始备份数据库{dbName}...");
string databaseBackupPath = $"{backupFolderPath}\\db.bak";
command = client.CreateCommand($"sqlcmd -S . -U \"{dbUser}\" -P \"{dbPwd}\" -Q \"BACKUP DATABASE [{dbName}] TO DISK='{databaseBackupPath}' WITH INIT\"");
command.Execute();
if (command.ExitStatus != 0)
{
throw new Exception("Failed to backup database.");
}
}
catch (Exception ex)
{
WinformLog($"{ex.Message}", Color.Red);
}
}
}

View File

@ -1,8 +1,10 @@
{
"BackUp": {
"DataBaseName": "IRaCIS_New_Tet",
"DBUser": "sa",
"DBPwd": "123456",
"BackPath": "D:\\Develop\\PublishSite\\发布备份",
"ProgramRootPath": "D:\\Develop\\PublishSite\\发布备份",
"ProgramRootPath": "D:\\Develop\\PublishSite\\IRaCIS.NetCore.API",
"ConnectionStrings": "Server=.;Database=IRaCIS;Trusted_Connection=True;TrustServerCertificate=true"
},
"Credential": {

View File

@ -1,7 +1,7 @@
{
"BackUp": {
"DataBaseName": "IRaCIS_New_Tet",
"FullDBRootPath": "Warning",
"BackPath": "Warning",
"ProgramRootPath": "D:\\Develop\\PublishSite\\发布备份",
"ConnectionStrings": "Server=.;Database=IRaCIS;Trusted_Connection=True;TrustServerCertificate=true"
},

View File

@ -1,7 +1,9 @@
{
"BackUp": {
"DataBaseName": "IRaCIS_New_Tet",
"FullDBRootPath": "Warning",
"DBUser": "sa",
"DBPwd": "123456",
"BackPath": "Warning",
"ProgramRootPath": "D:\\Develop\\PublishSite\\发布备份",
"ConnectionStrings": "Server=.;Database=IRaCIS;Trusted_Connection=True;TrustServerCertificate=true"
},

View File

@ -1,7 +1,7 @@
{
"BackUp": {
"DataBaseName": "IRaCIS_New_Tet",
"FullDBRootPath": "Warning",
"BackPath": "Warning",
"ProgramRootPath": "D:\\Develop\\PublishSite\\发布备份",
"ConnectionStrings": "Server=.;Database=IRaCIS;Trusted_Connection=True;TrustServerCertificate=true"
},