Backup: transfer to ASC.Data.Backup
This commit is contained in:
parent
ca9af1080c
commit
4e839c9b11
@ -30,7 +30,6 @@
|
||||
<ItemGroup>
|
||||
<None Remove="protos\AzRecordCache.proto" />
|
||||
<None Remove="protos\ConsumerCacheItem.proto" />
|
||||
<None Remove="protos\DeleteBackupRequest.proto" />
|
||||
<None Remove="protos\GroupCacheItem.proto" />
|
||||
<None Remove="protos\NotifyMessage.proto" />
|
||||
<None Remove="protos\QuotaCacheItem.proto" />
|
||||
@ -42,14 +41,6 @@
|
||||
<None Remove="protos\UserGroupRefCacheItem.proto" />
|
||||
<None Remove="protos\UserInfoCacheItem.proto" />
|
||||
<None Remove="protos\UserPhotoCacheItem.proto" />
|
||||
<None Remove="protos\BackupHistoryRecord.proto" />
|
||||
<None Remove="protos\BackupProgress.proto" />
|
||||
<None Remove="protos\CreateScheduleRequest.proto" />
|
||||
<None Remove="protos\ScheduleResponse.proto" />
|
||||
<None Remove="protos\StartBackupRequest.proto" />
|
||||
<None Remove="protos\StartRestoreRequest.proto" />
|
||||
<None Remove="protos\StartTransferRequest.proto" />
|
||||
<None Remove="protos\TransferRegion.proto" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AWSSDK.CloudFront" Version="3.3.101.153" />
|
||||
@ -70,7 +61,6 @@
|
||||
<Protobuf Include="protos\NotifyMessage.proto" />
|
||||
<Protobuf Include="protos\SettingsCacheItem.proto" />
|
||||
<Protobuf Include="protos\ConsumerCacheItem.proto" />
|
||||
<Protobuf Include="protos\DeleteBackupRequest.proto" />
|
||||
<Protobuf Include="protos\TenantCacheItem.proto" />
|
||||
<Protobuf Include="protos\GroupCacheItem.proto" />
|
||||
<Protobuf Include="protos\UserGroupRefCacheItem.proto" />
|
||||
@ -82,13 +72,5 @@
|
||||
<Protobuf Include="protos\TariffCacheItem.proto" />
|
||||
<Protobuf Include="protos\AzRecordCache.proto" />
|
||||
<Protobuf Include="protos\QuotaCacheItem.proto" />
|
||||
<Protobuf Include="protos\BackupHistoryRecord.proto" />
|
||||
<Protobuf Include="protos\BackupProgress.proto" />
|
||||
<Protobuf Include="protos\CreateScheduleRequest.proto" />
|
||||
<Protobuf Include="protos\ScheduleResponse.proto" />
|
||||
<Protobuf Include="protos\StartBackupRequest.proto" />
|
||||
<Protobuf Include="protos\StartRestoreRequest.proto" />
|
||||
<Protobuf Include="protos\StartTransferRequest.proto" />
|
||||
<Protobuf Include="protos\TransferRegion.proto" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -12,9 +12,26 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SharpCompress" Version="0.25.0" />
|
||||
<None Remove="protos\BackupHistoryRecord.proto" />
|
||||
<None Remove="protos\BackupProgress.proto" />
|
||||
<None Remove="protos\CreateScheduleRequest.proto" />
|
||||
<None Remove="protos\DeleteBackupRequest.proto" />
|
||||
<None Remove="protos\ScheduleResponse.proto" />
|
||||
<None Remove="protos\StartBackupRequest.proto" />
|
||||
<None Remove="protos\StartRestoreRequest.proto" />
|
||||
<None Remove="protos\StartTransferRequest.proto" />
|
||||
<None Remove="protos\TransferRegion.proto" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Protobuf" Version="3.12.3" />
|
||||
<PackageReference Include="Grpc" Version="2.29.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.29.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="SharpCompress" Version="0.25.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\products\ASC.Files\Server\ASC.Files.csproj" />
|
||||
<ProjectReference Include="..\..\ASC.Common\ASC.Common.csproj" />
|
||||
@ -22,12 +39,24 @@
|
||||
<ProjectReference Include="..\..\ASC.Data.Storage\ASC.Data.Storage.csproj" />
|
||||
<ProjectReference Include="..\ASC.Notify\ASC.Notify.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Protobuf Include="protos\BackupHistoryRecord.proto" />
|
||||
<Protobuf Include="protos\BackupProgress.proto" />
|
||||
<Protobuf Include="protos\CreateScheduleRequest.proto" />
|
||||
<Protobuf Include="protos\DeleteBackupRequest.proto" />
|
||||
<Protobuf Include="protos\ScheduleResponse.proto" />
|
||||
<Protobuf Include="protos\StartBackupRequest.proto" />
|
||||
<Protobuf Include="protos\StartRestoreRequest.proto" />
|
||||
<Protobuf Include="protos\StartTransferRequest.proto" />
|
||||
<Protobuf Include="protos\TransferRegion.proto" />
|
||||
</ItemGroup>
|
||||
<Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
|
||||
<ItemGroup>
|
||||
<ReferencePath Condition="'%(FileName)' == 'MySqlConnector'">
|
||||
<Aliases>MySqlConnectorAlias</Aliases>
|
||||
</ReferencePath>
|
||||
</ItemGroup>
|
||||
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -6,8 +6,9 @@ using ASC.Common;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Billing;
|
||||
using ASC.Core.Common.Configuration;
|
||||
using ASC.Core.Common.Contracts;
|
||||
using ASC.Core.Users;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
using ASC.Data.Backup.Service;
|
||||
using ASC.MessagingSystem;
|
||||
using ASC.Notify.Cron;
|
||||
using ASC.Web.Core.PublicResources;
|
||||
@ -29,11 +30,11 @@ namespace ASC.Data.Backup
|
||||
private TenantExtra TenantExtra { get; }
|
||||
private BackupHelper BackupHelper { get; }
|
||||
private ConsumerFactory ConsumerFactory { get; }
|
||||
private BackupServiceClient BackupServiceClient { get; }
|
||||
private BackupService BackupService { get; }
|
||||
|
||||
#region backup
|
||||
|
||||
public BackupAjaxHandler(BackupServiceClient backupServiceClient, TenantManager tenantManager, MessageService messageService, CoreBaseSettings coreBaseSettings, CoreConfiguration coreConfiguration, PermissionContext permissionContext, SecurityContext securityContext, UserManager userManager, TenantExtra tenantExtra, BackupHelper backupHelper, ConsumerFactory consumerFactory)
|
||||
public BackupAjaxHandler(BackupService backupService, TenantManager tenantManager, MessageService messageService, CoreBaseSettings coreBaseSettings, CoreConfiguration coreConfiguration, PermissionContext permissionContext, SecurityContext securityContext, UserManager userManager, TenantExtra tenantExtra, BackupHelper backupHelper, ConsumerFactory consumerFactory)
|
||||
{
|
||||
TenantManager = tenantManager;
|
||||
MessageService = messageService;
|
||||
@ -45,7 +46,7 @@ namespace ASC.Data.Backup
|
||||
TenantExtra = tenantExtra;
|
||||
BackupHelper = backupHelper;
|
||||
ConsumerFactory = consumerFactory;
|
||||
BackupServiceClient = backupServiceClient;
|
||||
BackupService = backupService;
|
||||
}
|
||||
|
||||
public void StartBackup(BackupStorageType storageType, Dictionary<string, string> storageParams, bool backupMail)
|
||||
@ -76,34 +77,34 @@ namespace ASC.Data.Backup
|
||||
|
||||
MessageService.Send(MessageAction.StartBackupSetting);
|
||||
|
||||
BackupServiceClient.StartBackup(backupRequest);
|
||||
BackupService.StartBackup(backupRequest);
|
||||
}
|
||||
|
||||
public BackupProgress GetBackupProgress()
|
||||
{
|
||||
DemandPermissionsBackup();
|
||||
|
||||
return BackupServiceClient.GetBackupProgress(GetCurrentTenantId());
|
||||
return BackupService.GetBackupProgress(GetCurrentTenantId());
|
||||
}
|
||||
|
||||
public void DeleteBackup(Guid id)
|
||||
{
|
||||
DemandPermissionsBackup();
|
||||
|
||||
BackupServiceClient.DeleteBackup(id);
|
||||
BackupService.DeleteBackup(id);
|
||||
}
|
||||
|
||||
public void DeleteAllBackups()
|
||||
{
|
||||
DemandPermissionsBackup();
|
||||
|
||||
BackupServiceClient.DeleteAllBackups(GetCurrentTenantId());
|
||||
BackupService.DeleteAllBackups(GetCurrentTenantId());
|
||||
}
|
||||
|
||||
public List<BackupHistoryRecord> GetBackupHistory()
|
||||
{
|
||||
DemandPermissionsBackup();
|
||||
return BackupServiceClient.GetBackupHistory(GetCurrentTenantId());
|
||||
return BackupService.GetBackupHistory(GetCurrentTenantId());
|
||||
}
|
||||
|
||||
public void CreateSchedule(BackupStorageType storageType, Dictionary<string, string> storageParams, int backupsStored, CronParams cronParams, bool backupMail)
|
||||
@ -137,7 +138,7 @@ namespace ASC.Data.Backup
|
||||
break;
|
||||
}
|
||||
|
||||
BackupServiceClient.CreateSchedule(scheduleRequest);
|
||||
BackupService.CreateSchedule(scheduleRequest);
|
||||
}
|
||||
|
||||
public Schedule GetSchedule()
|
||||
@ -146,7 +147,7 @@ namespace ASC.Data.Backup
|
||||
|
||||
ScheduleResponse response;
|
||||
|
||||
response = BackupServiceClient.GetSchedule(GetCurrentTenantId());
|
||||
response = BackupService.GetSchedule(GetCurrentTenantId());
|
||||
if (response == null)
|
||||
{
|
||||
return null;
|
||||
@ -189,7 +190,7 @@ namespace ASC.Data.Backup
|
||||
StorageType = (int)schedule.StorageType
|
||||
};
|
||||
Schedule.StorageParams.Add(schedule.StorageParams);
|
||||
BackupServiceClient.CreateSchedule(Schedule);
|
||||
BackupService.CreateSchedule(Schedule);
|
||||
|
||||
}
|
||||
else if ((BackupStorageType)response.StorageType != BackupStorageType.ThirdPartyConsumer)
|
||||
@ -204,7 +205,7 @@ namespace ASC.Data.Backup
|
||||
{
|
||||
DemandPermissionsBackup();
|
||||
|
||||
BackupServiceClient.DeleteSchedule(GetCurrentTenantId());
|
||||
BackupService.DeleteSchedule(GetCurrentTenantId());
|
||||
|
||||
}
|
||||
|
||||
@ -239,7 +240,7 @@ namespace ASC.Data.Backup
|
||||
restoreRequest.StorageType = (int)storageType;
|
||||
restoreRequest.FilePathOrId = storageParams["filePath"];
|
||||
}
|
||||
BackupServiceClient.StartRestore(restoreRequest);
|
||||
BackupService.StartRestore(restoreRequest);
|
||||
}
|
||||
|
||||
public BackupProgress GetRestoreProgress()
|
||||
@ -247,7 +248,7 @@ namespace ASC.Data.Backup
|
||||
BackupProgress result;
|
||||
|
||||
var tenant = TenantManager.GetCurrentTenant();
|
||||
result = BackupServiceClient.GetRestoreProgress(tenant.TenantId);
|
||||
result = BackupService.GetRestoreProgress(tenant.TenantId);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -270,7 +271,7 @@ namespace ASC.Data.Backup
|
||||
DemandSize();
|
||||
|
||||
MessageService.Send(MessageAction.StartTransferSetting);
|
||||
BackupServiceClient.StartTransfer(
|
||||
BackupService.StartTransfer(
|
||||
new StartTransferRequest
|
||||
{
|
||||
TenantId = GetCurrentTenantId(),
|
||||
@ -283,7 +284,7 @@ namespace ASC.Data.Backup
|
||||
|
||||
public BackupProgress GetTransferProgress()
|
||||
{
|
||||
return BackupServiceClient.GetTransferProgress(GetCurrentTenantId());
|
||||
return BackupService.GetTransferProgress(GetCurrentTenantId());
|
||||
}
|
||||
|
||||
private void DemandPermissionsTransfer()
|
||||
@ -301,7 +302,7 @@ namespace ASC.Data.Backup
|
||||
|
||||
public string GetTmpFolder()
|
||||
{
|
||||
return BackupServiceClient.GetTmpFolder();
|
||||
return BackupService.GetTmpFolder();
|
||||
}
|
||||
|
||||
private void DemandSize()
|
||||
|
@ -41,25 +41,21 @@ namespace ASC.Data.Backup.Service
|
||||
private BackupSchedulerService SchedulerService { get; set; }
|
||||
private BackupWorker BackupWorker { get; set; }
|
||||
private IConfiguration Configuration { get; set; }
|
||||
private BackupServiceNotifier BackupServiceNotifier { get; }
|
||||
|
||||
public BackupServiceLauncher(
|
||||
BackupCleanerService cleanerService,
|
||||
BackupSchedulerService schedulerService,
|
||||
BackupWorker backupWorker,
|
||||
IConfiguration configuration,
|
||||
BackupServiceNotifier backupServiceNotifier)
|
||||
IConfiguration configuration)
|
||||
{
|
||||
CleanerService = cleanerService;
|
||||
SchedulerService = schedulerService;
|
||||
BackupWorker = backupWorker;
|
||||
Configuration = configuration;
|
||||
BackupServiceNotifier = backupServiceNotifier;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
BackupServiceNotifier.Subscribe();
|
||||
var settings = Configuration.GetSetting<BackupSettings>("backup");
|
||||
|
||||
BackupWorker.Start(settings);
|
||||
|
@ -32,7 +32,7 @@ using ASC.Common.Caching;
|
||||
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace ASC.Core.Common.Contracts
|
||||
namespace ASC.Data.Backup.Contracts
|
||||
{
|
||||
public class BackupServiceClient : IBackupService
|
||||
{
|
@ -26,22 +26,21 @@
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.Core.Common.Contracts
|
||||
namespace ASC.Data.Backup.Contracts
|
||||
{
|
||||
[DataContract]
|
||||
public enum BackupStorageType
|
||||
{
|
||||
[EnumMember] Documents = 0,
|
||||
Documents = 0,
|
||||
|
||||
[EnumMember] ThridpartyDocuments = 1,
|
||||
ThridpartyDocuments = 1,
|
||||
|
||||
[EnumMember] CustomCloud = 2,
|
||||
CustomCloud = 2,
|
||||
|
||||
[EnumMember] Local = 3,
|
||||
Local = 3,
|
||||
|
||||
[EnumMember] DataStore = 4,
|
||||
DataStore = 4,
|
||||
|
||||
[EnumMember] ThirdPartyConsumer = 5
|
||||
ThirdPartyConsumer = 5
|
||||
}
|
||||
/*
|
||||
[DataContract]
|
@ -28,7 +28,9 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceModel;
|
||||
|
||||
namespace ASC.Core.Common.Contracts
|
||||
using ASC.Data.Backup.Contracts;
|
||||
|
||||
namespace ASC.Data.Backup.Contracts
|
||||
{
|
||||
[ServiceContract]
|
||||
public interface IBackupService
|
160
common/services/ASC.Data.Backup/Controllers/BackupController.cs
Normal file
160
common/services/ASC.Data.Backup/Controllers/BackupController.cs
Normal file
@ -0,0 +1,160 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
using ASC.Web.Api.Routing;
|
||||
using ASC.Data.Backup.Models;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ASC.Common;
|
||||
using ASC.Api.Core.Middleware;
|
||||
|
||||
namespace ASC.Data.Backup.Controllers
|
||||
{
|
||||
[DefaultRoute]
|
||||
[ApiController]
|
||||
public class BackupController
|
||||
{
|
||||
public BackupAjaxHandler BackupHandler { get; }
|
||||
public BackupController(BackupAjaxHandler backupAjaxHandler)
|
||||
{
|
||||
BackupHandler = backupAjaxHandler;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the backup schedule of the current portal
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup Schedule</returns>
|
||||
[Read("getbackupschedule")]
|
||||
public BackupAjaxHandler.Schedule GetBackupSchedule()
|
||||
{
|
||||
return BackupHandler.GetSchedule();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create the backup schedule of the current portal
|
||||
/// </summary>
|
||||
/// <param name="storageType">Storage type</param>
|
||||
/// <param name="storageParams">Storage parameters</param>
|
||||
/// <param name="backupsStored">Max of the backup's stored copies</param>
|
||||
/// <param name="cronParams">Cron parameters</param>
|
||||
/// <param name="backupMail">Include mail in the backup</param>
|
||||
/// <category>Backup</category>
|
||||
[Create("createbackupschedule")]
|
||||
public void CreateBackupSchedule(BackupStorageType storageType, [FromQuery] Dictionary<string, string> storageParams, int backupsStored, [FromBody] BackupAjaxHandler.CronParams cronParams, bool backupMail)
|
||||
{
|
||||
BackupHandler.CreateSchedule(storageType, storageParams, backupsStored, cronParams, backupMail);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the backup schedule of the current portal
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
[Delete("deletebackupschedule")]
|
||||
public void DeleteBackupSchedule()
|
||||
{
|
||||
BackupHandler.DeleteSchedule();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start a backup of the current portal
|
||||
/// </summary>
|
||||
/// <param name="storageType">Storage Type</param>
|
||||
/// <param name="storageParams">Storage Params</param>
|
||||
/// <param name="backupMail">Include mail in the backup</param>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup Progress</returns>
|
||||
[Create("startbackup")]
|
||||
public BackupProgress StartBackup(Models.Backup backup)
|
||||
{
|
||||
BackupHandler.StartBackup(backup.StorageType, backup.StorageParams ?? new Dictionary<string, string>(), backup.BackupMail);
|
||||
return BackupHandler.GetBackupProgress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the progress of the started backup
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup Progress</returns>
|
||||
[Read("getbackupprogress")]
|
||||
public BackupProgress GetBackupProgress()
|
||||
{
|
||||
return BackupHandler.GetBackupProgress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the backup history of the started backup
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup History</returns>
|
||||
[Read("getbackuphistory")]
|
||||
public List<BackupHistoryRecord> GetBackupHistory()
|
||||
{
|
||||
return BackupHandler.GetBackupHistory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the backup with the specified id
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
[Delete("deletebackup/{id}")]
|
||||
public void DeleteBackup(Guid id)
|
||||
{
|
||||
BackupHandler.DeleteBackup(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete all backups of the current portal
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup History</returns>
|
||||
[Delete("deletebackuphistory")]
|
||||
public void DeleteBackupHistory()
|
||||
{
|
||||
BackupHandler.DeleteAllBackups();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start a data restore of the current portal
|
||||
/// </summary>
|
||||
/// <param name="backupId">Backup Id</param>
|
||||
/// <param name="storageType">Storage Type</param>
|
||||
/// <param name="storageParams">Storage Params</param>
|
||||
/// <param name="notify">Notify about backup to users</param>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Restore Progress</returns>
|
||||
[Create("startrestore")]
|
||||
public BackupProgress StartBackupRestore(BackupRestore backupRestore)
|
||||
{
|
||||
BackupHandler.StartRestore(backupRestore.BackupId, backupRestore.StorageType, backupRestore.StorageParams, backupRestore.Notify);
|
||||
return BackupHandler.GetBackupProgress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the progress of the started restore
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Restore Progress</returns>
|
||||
[Read("getrestoreprogress", true)] //NOTE: this method doesn't check payment!!!
|
||||
public BackupProgress GetRestoreProgress()
|
||||
{
|
||||
return BackupHandler.GetRestoreProgress();
|
||||
}
|
||||
|
||||
///<visible>false</visible>
|
||||
[Read("backuptmp")]
|
||||
public string GetTempPath()
|
||||
{
|
||||
return BackupHandler.GetTmpFolder();
|
||||
}
|
||||
}
|
||||
public static class BackupControllerExtension
|
||||
{
|
||||
public static DIHelper AddBackupController(this DIHelper services)
|
||||
{
|
||||
return services
|
||||
.AddBackupAjaxHandler()
|
||||
.AddIpSecurityFilter();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
using ASC.Core.Common.Contracts;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
|
||||
namespace ASC.Data.Backup.EF.Model
|
||||
{
|
@ -2,9 +2,8 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
using ASC.Core.Common.Contracts;
|
||||
using ASC.Core.Common.EF;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
|
||||
namespace ASC.Data.Backup.EF.Model
|
||||
{
|
13
common/services/ASC.Data.Backup/ModelApi/Backup.cs
Normal file
13
common/services/ASC.Data.Backup/ModelApi/Backup.cs
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
|
||||
namespace ASC.Data.Backup.Models
|
||||
{
|
||||
public class Backup
|
||||
{
|
||||
public BackupStorageType StorageType { get; set; }
|
||||
public bool BackupMail { get; set; }
|
||||
public Dictionary<string, string> StorageParams { get; set; }
|
||||
}
|
||||
}
|
17
common/services/ASC.Data.Backup/ModelApi/BackupRestore.cs
Normal file
17
common/services/ASC.Data.Backup/ModelApi/BackupRestore.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ASC.Data.Backup.Contracts;
|
||||
|
||||
namespace ASC.Data.Backup.Models
|
||||
{
|
||||
public class BackupRestore
|
||||
{
|
||||
public string BackupId { get; set; }
|
||||
public BackupStorageType StorageType { get; set; }
|
||||
public Dictionary<string, string> StorageParams { get; set; }
|
||||
public bool Notify { get; set; }
|
||||
}
|
||||
}
|
@ -7,8 +7,10 @@ using ASC.Common;
|
||||
using ASC.Common.DependencyInjection;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Common.Threading.Progress;
|
||||
using ASC.Data.Backup.Controllers;
|
||||
using ASC.Data.Backup.Service;
|
||||
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@ -20,6 +22,10 @@ namespace ASC.Data.Backup
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var host = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
})
|
||||
.ConfigureAppConfiguration((hostContext, config) =>
|
||||
{
|
||||
var buided = config.Build();
|
||||
@ -50,7 +56,8 @@ namespace ASC.Data.Backup
|
||||
{
|
||||
var diHelper = new DIHelper(services);
|
||||
|
||||
diHelper.AddBackupServiceLauncher();
|
||||
diHelper.AddBackupServiceLauncher()
|
||||
.AddBackupController();
|
||||
diHelper.AddNLogManager("ASC.Data.Backup");
|
||||
services.AddHostedService<BackupServiceLauncher>();
|
||||
diHelper.Configure<ProgressQueue<BaseBackupProgressItem>>(r =>
|
||||
|
@ -34,7 +34,7 @@ using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Common.Utils;
|
||||
using ASC.Core.Common.Contracts;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
using ASC.Data.Backup.EF.Model;
|
||||
using ASC.Data.Backup.Storage;
|
||||
using ASC.Data.Backup.Utils;
|
||||
@ -123,7 +123,7 @@ namespace ASC.Data.Backup.Service
|
||||
}
|
||||
}
|
||||
|
||||
internal class BackupService : IBackupService
|
||||
public class BackupService : IBackupService
|
||||
{
|
||||
private ILog Log { get; set; }
|
||||
private BackupStorageFactory BackupStorageFactory { get; set; }
|
||||
@ -334,7 +334,7 @@ namespace ASC.Data.Backup.Service
|
||||
services.TryAddScoped<BackupService>();
|
||||
services.TryAddSingleton<BackupServiceNotifier>();
|
||||
return services
|
||||
.AddKafkaService();
|
||||
.AddBackupWorkerService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,8 +36,8 @@ using ASC.Common.Logging;
|
||||
using ASC.Common.Threading.Progress;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Billing;
|
||||
using ASC.Core.Common.Contracts;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
using ASC.Data.Backup.EF.Model;
|
||||
using ASC.Data.Backup.Storage;
|
||||
using ASC.Data.Backup.Tasks;
|
||||
@ -52,7 +52,7 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace ASC.Data.Backup.Service
|
||||
{
|
||||
internal class BackupWorker
|
||||
public class BackupWorker
|
||||
{
|
||||
private ILog Log { get; set; }
|
||||
private ProgressQueue<BaseBackupProgressItem> ProgressQueue { get; set; }
|
||||
@ -73,7 +73,7 @@ namespace ASC.Data.Backup.Service
|
||||
Log = options.CurrentValue;
|
||||
ProgressQueue = progressQueue.Value;
|
||||
CacheBackupProgress = cacheBackupProgress;
|
||||
this.FactoryProgressItem = factoryProgressItem;
|
||||
FactoryProgressItem = factoryProgressItem;
|
||||
}
|
||||
|
||||
public void Start(BackupSettings settings)
|
||||
@ -771,9 +771,9 @@ namespace ASC.Data.Backup.Service
|
||||
{
|
||||
services.TryAddSingleton<BackupWorker>();
|
||||
services.TryAddSingleton<FactoryProgressItem>();
|
||||
services.TryAddScoped<BackupProgressItem>();
|
||||
services.TryAddScoped<TransferProgressItem>();
|
||||
services.TryAddScoped<RestoreProgressItem>();
|
||||
services.TryAddTransient<BackupProgressItem>();
|
||||
services.TryAddTransient<TransferProgressItem>();
|
||||
services.TryAddTransient<RestoreProgressItem>();
|
||||
|
||||
|
||||
services.TryAddSingleton<ProgressQueueOptionsManager<BaseBackupProgressItem>>();
|
||||
|
105
common/services/ASC.Data.Backup/Startup.cs
Normal file
105
common/services/ASC.Data.Backup/Startup.cs
Normal file
@ -0,0 +1,105 @@
|
||||
|
||||
using ASC.Api.Core;
|
||||
using ASC.Api.Core.Auth;
|
||||
using ASC.Api.Core.Core;
|
||||
using ASC.Api.Core.Middleware;
|
||||
using ASC.Common;
|
||||
using ASC.Common.DependencyInjection;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Data.Backup.Controllers;
|
||||
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace ASC.Data.Backup
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public IConfiguration Configuration { get; }
|
||||
public IHostEnvironment HostEnvironment { get; }
|
||||
|
||||
public Startup(IConfiguration configuration, IHostEnvironment hostEnvironment)
|
||||
{
|
||||
Configuration = configuration;
|
||||
HostEnvironment = hostEnvironment;
|
||||
}
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
services.AddControllers()
|
||||
.AddXmlSerializerFormatters()
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.WriteIndented = false;
|
||||
options.JsonSerializerOptions.IgnoreNullValues = true;
|
||||
options.JsonSerializerOptions.Converters.Add(new ApiDateTimeConverter());
|
||||
});
|
||||
|
||||
services.AddAuthentication("cookie")
|
||||
.AddScheme<AuthenticationSchemeOptions, CookieAuthHandler>("cookie", a => { })
|
||||
.AddScheme<AuthenticationSchemeOptions, ConfirmAuthHandler>("confirm", a => { });
|
||||
|
||||
var builder = services.AddMvcCore(config =>
|
||||
{
|
||||
var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
|
||||
config.Filters.Add(new AuthorizeFilter(policy));
|
||||
config.Filters.Add(new TypeFilterAttribute(typeof(TenantStatusFilter)));
|
||||
config.Filters.Add(new TypeFilterAttribute(typeof(PaymentFilter)));
|
||||
config.Filters.Add(new TypeFilterAttribute(typeof(IpSecurityFilter)));
|
||||
config.Filters.Add(new TypeFilterAttribute(typeof(ProductSecurityFilter)));
|
||||
config.Filters.Add(new CustomResponseFilterAttribute());
|
||||
config.Filters.Add(new CustomExceptionFilterAttribute());
|
||||
config.Filters.Add(new TypeFilterAttribute(typeof(FormatFilter)));
|
||||
|
||||
config.OutputFormatters.RemoveType<XmlSerializerOutputFormatter>();
|
||||
config.OutputFormatters.Add(new XmlOutputFormatter());
|
||||
});
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
||||
{
|
||||
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||
});
|
||||
|
||||
app.UseCors(builder =>
|
||||
builder
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod());
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseCultureMiddleware();
|
||||
|
||||
app.UseDisposeMiddleware();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
endpoints.MapCustom();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ using System.Collections.Generic;
|
||||
using ASC.Common;
|
||||
using ASC.Common.Utils;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Common.Contracts;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
using ASC.Data.Backup.EF.Model;
|
||||
using ASC.Data.Backup.Service;
|
||||
using ASC.Data.Backup.Utils;
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ASC.Core.Common.Contracts;
|
||||
package ASC.Data.Backup.Contracts;
|
||||
import "google/protobuf/timestamp.proto";
|
||||
message BackupHistoryRecord {
|
||||
string Id = 1;
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ASC.Core.Common.Contracts;
|
||||
package ASC.Data.Backup.Contracts;
|
||||
|
||||
message BackupProgress {
|
||||
bool IsCompleted = 1;
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ASC.Core.Common.Contracts;
|
||||
package ASC.Data.Backup.Contracts;
|
||||
|
||||
message CreateScheduleRequest {
|
||||
int32 TenantId = 1;
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ASC.Core.Common.Contracts;
|
||||
package ASC.Data.Backup.Contracts;
|
||||
|
||||
message DeleteBackupRequest {
|
||||
int32 TenantId = 1;
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ASC.Core.Common.Contracts;
|
||||
package ASC.Data.Backup.Contracts;
|
||||
import "google/protobuf/timestamp.proto";
|
||||
message ScheduleResponse {
|
||||
int32 StorageType = 1;
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ASC.Core.Common.Contracts;
|
||||
package ASC.Data.Backup.Contracts;
|
||||
|
||||
message StartBackupRequest {
|
||||
int32 TenantId = 1;
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ASC.Core.Common.Contracts;
|
||||
package ASC.Data.Backup.Contracts;
|
||||
|
||||
message StartRestoreRequest {
|
||||
int32 TenantId = 1;
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ASC.Core.Common.Contracts;
|
||||
package ASC.Data.Backup.Contracts;
|
||||
|
||||
message StartTransferRequest {
|
||||
int32 TenantId = 1;
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ASC.Core.Common.Contracts;
|
||||
package ASC.Data.Backup.Contracts;
|
||||
|
||||
message TransferRegion {
|
||||
string Name = 1;
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
|
||||
@ -8,13 +7,10 @@ using ASC.Common;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Billing;
|
||||
using ASC.Core.Common.Contracts;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.Core.Users;
|
||||
using ASC.Data.Backup;
|
||||
using ASC.MessagingSystem;
|
||||
using ASC.Security.Cryptography;
|
||||
using ASC.Web.Api.Models;
|
||||
using ASC.Web.Api.Routing;
|
||||
using ASC.Web.Core;
|
||||
using ASC.Web.Core.Utility;
|
||||
@ -30,7 +26,6 @@ namespace ASC.Web.Api.Controllers
|
||||
[ApiController]
|
||||
public class PortalController : ControllerBase
|
||||
{
|
||||
public BackupAjaxHandler BackupHandler { get; }
|
||||
|
||||
public Tenant Tenant { get { return ApiContext.Tenant; } }
|
||||
|
||||
@ -54,8 +49,7 @@ namespace ASC.Web.Api.Controllers
|
||||
CommonLinkUtility commonLinkUtility,
|
||||
UrlShortener urlShortener,
|
||||
AuthContext authContext,
|
||||
WebItemSecurity webItemSecurity,
|
||||
BackupAjaxHandler backupHandler
|
||||
WebItemSecurity webItemSecurity
|
||||
)
|
||||
{
|
||||
Log = options.CurrentValue;
|
||||
@ -67,7 +61,6 @@ namespace ASC.Web.Api.Controllers
|
||||
UrlShortener = urlShortener;
|
||||
AuthContext = authContext;
|
||||
WebItemSecurity = webItemSecurity;
|
||||
BackupHandler = backupHandler;
|
||||
}
|
||||
|
||||
[Read("")]
|
||||
@ -157,133 +150,7 @@ namespace ASC.Web.Api.Controllers
|
||||
return CommonLinkUtility.GetFullAbsolutePath(virtualPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the backup schedule of the current portal
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup Schedule</returns>
|
||||
[Read("getbackupschedule")]
|
||||
public BackupAjaxHandler.Schedule GetBackupSchedule()
|
||||
{
|
||||
return BackupHandler.GetSchedule();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create the backup schedule of the current portal
|
||||
/// </summary>
|
||||
/// <param name="storageType">Storage type</param>
|
||||
/// <param name="storageParams">Storage parameters</param>
|
||||
/// <param name="backupsStored">Max of the backup's stored copies</param>
|
||||
/// <param name="cronParams">Cron parameters</param>
|
||||
/// <param name="backupMail">Include mail in the backup</param>
|
||||
/// <category>Backup</category>
|
||||
[Create("createbackupschedule")]
|
||||
public void CreateBackupSchedule(BackupStorageType storageType, [FromQuery] Dictionary<string, string> storageParams, int backupsStored, [FromBody] BackupAjaxHandler.CronParams cronParams, bool backupMail)
|
||||
{
|
||||
BackupHandler.CreateSchedule(storageType, storageParams, backupsStored, cronParams, backupMail);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the backup schedule of the current portal
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
[Delete("deletebackupschedule")]
|
||||
public void DeleteBackupSchedule()
|
||||
{
|
||||
BackupHandler.DeleteSchedule();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start a backup of the current portal
|
||||
/// </summary>
|
||||
/// <param name="storageType">Storage Type</param>
|
||||
/// <param name="storageParams">Storage Params</param>
|
||||
/// <param name="backupMail">Include mail in the backup</param>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup Progress</returns>
|
||||
[Create("startbackup")]
|
||||
public BackupProgress StartBackup(Backup backup)
|
||||
{
|
||||
BackupHandler.StartBackup(backup.StorageType, backup.StorageParams ?? new Dictionary<string, string>(), backup.BackupMail);
|
||||
return BackupHandler.GetBackupProgress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the progress of the started backup
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup Progress</returns>
|
||||
[Read("getbackupprogress")]
|
||||
public BackupProgress GetBackupProgress()
|
||||
{
|
||||
return BackupHandler.GetBackupProgress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the backup history of the started backup
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup History</returns>
|
||||
[Read("getbackuphistory")]
|
||||
public List<BackupHistoryRecord> GetBackupHistory()
|
||||
{
|
||||
return BackupHandler.GetBackupHistory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the backup with the specified id
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
[Delete("deletebackup/{id}")]
|
||||
public void DeleteBackup(Guid id)
|
||||
{
|
||||
BackupHandler.DeleteBackup(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete all backups of the current portal
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup History</returns>
|
||||
[Delete("deletebackuphistory")]
|
||||
public void DeleteBackupHistory()
|
||||
{
|
||||
BackupHandler.DeleteAllBackups();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start a data restore of the current portal
|
||||
/// </summary>
|
||||
/// <param name="backupId">Backup Id</param>
|
||||
/// <param name="storageType">Storage Type</param>
|
||||
/// <param name="storageParams">Storage Params</param>
|
||||
/// <param name="notify">Notify about backup to users</param>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Restore Progress</returns>
|
||||
[Create("startrestore")]
|
||||
public BackupProgress StartBackupRestore(BackupRestore backupRestore)
|
||||
{
|
||||
BackupHandler.StartRestore(backupRestore.BackupId, backupRestore.StorageType, backupRestore.StorageParams, backupRestore.Notify);
|
||||
return BackupHandler.GetBackupProgress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the progress of the started restore
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Restore Progress</returns>
|
||||
[Read("getrestoreprogress", true)] //NOTE: this method doesn't check payment!!!
|
||||
public BackupProgress GetRestoreProgress()
|
||||
{
|
||||
return BackupHandler.GetRestoreProgress();
|
||||
}
|
||||
|
||||
///<visible>false</visible>
|
||||
[Read("backuptmp")]
|
||||
public string GetTempPath(string alias)
|
||||
{
|
||||
return BackupHandler.GetTmpFolder();
|
||||
}
|
||||
}
|
||||
|
||||
public static class PortalControllerExtension
|
||||
@ -303,8 +170,7 @@ namespace ASC.Web.Api.Controllers
|
||||
.AddPaymentManagerService()
|
||||
.AddCommonLinkUtilityService()
|
||||
.AddAuthContextService()
|
||||
.AddWebItemSecurity()
|
||||
.AddBackupAjaxHandler();
|
||||
.AddWebItemSecurity();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
using System;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ASC.Core.Common.Contracts;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
|
||||
namespace ASC.Web.Api.Models
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user