2022-08-10 09:25:53 +00:00
|
|
|
|
// (c) Copyright Ascensio System SIA 2010-2022
|
|
|
|
|
//
|
|
|
|
|
// This program is a free software product.
|
|
|
|
|
// You can redistribute it and/or modify it under the terms
|
|
|
|
|
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
|
|
|
|
|
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
|
|
|
|
|
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
|
|
|
|
|
// any third-party rights.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
|
|
|
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
|
|
|
|
|
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
|
//
|
|
|
|
|
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
|
|
|
|
|
//
|
|
|
|
|
// The interactive user interfaces in modified source and object code versions of the Program must
|
|
|
|
|
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
|
|
|
|
|
//
|
|
|
|
|
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
|
|
|
|
|
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
|
|
|
|
|
// trademark law for use of our trademarks.
|
|
|
|
|
//
|
|
|
|
|
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
|
|
|
|
|
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
|
|
|
|
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
|
|
|
|
2022-11-29 13:38:44 +00:00
|
|
|
|
using CommandLine;
|
|
|
|
|
|
2022-08-10 09:25:53 +00:00
|
|
|
|
var options = new WebApplicationOptions
|
|
|
|
|
{
|
|
|
|
|
Args = args,
|
|
|
|
|
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-29 14:05:43 +00:00
|
|
|
|
var param = Parser.Default.ParseArguments<Options>(args).Value;
|
2022-11-30 16:03:44 +00:00
|
|
|
|
/*var param = new Options()
|
|
|
|
|
{
|
|
|
|
|
FromRegion = "personal",
|
2022-12-28 15:18:10 +00:00
|
|
|
|
ToRegion = "personal",
|
|
|
|
|
Tenant = 1,
|
2022-11-30 16:03:44 +00:00
|
|
|
|
UserName = "administrator"
|
|
|
|
|
};*/
|
2022-11-29 13:38:44 +00:00
|
|
|
|
|
2022-08-10 09:25:53 +00:00
|
|
|
|
var builder = WebApplication.CreateBuilder(options);
|
|
|
|
|
|
2022-12-07 14:28:40 +00:00
|
|
|
|
builder.WebHost.ConfigureAppConfiguration((hostContext, config) =>
|
|
|
|
|
{
|
|
|
|
|
config.AddJsonFile($"appsettings.personalToDocspace.json", true);
|
|
|
|
|
});
|
2022-08-14 22:12:59 +00:00
|
|
|
|
var config = builder.Configuration;
|
2022-08-10 09:25:53 +00:00
|
|
|
|
|
2022-12-07 14:28:40 +00:00
|
|
|
|
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
|
|
|
|
|
2022-08-10 09:25:53 +00:00
|
|
|
|
builder.WebHost.ConfigureServices((hostContext, services) =>
|
|
|
|
|
{
|
2022-11-30 16:03:44 +00:00
|
|
|
|
RegionSettings.SetCurrent(param.FromRegion);
|
2022-11-07 12:58:11 +00:00
|
|
|
|
|
2022-11-30 16:03:44 +00:00
|
|
|
|
services.RegisterFeature();
|
2022-08-10 09:25:53 +00:00
|
|
|
|
services.AddScoped<EFLoggerFactory>();
|
|
|
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
|
|
services.AddHttpClient();
|
|
|
|
|
services.AddBaseDbContextPool<AccountLinkContext>();
|
|
|
|
|
services.AddBaseDbContextPool<BackupsContext>();
|
|
|
|
|
services.AddBaseDbContextPool<FilesDbContext>();
|
|
|
|
|
services.AddBaseDbContextPool<CoreDbContext>();
|
|
|
|
|
services.AddBaseDbContextPool<TenantDbContext>();
|
|
|
|
|
services.AddBaseDbContextPool<UserDbContext>();
|
|
|
|
|
services.AddBaseDbContextPool<TelegramDbContext>();
|
|
|
|
|
services.AddBaseDbContextPool<CustomDbContext>();
|
|
|
|
|
services.AddBaseDbContextPool<WebstudioDbContext>();
|
|
|
|
|
services.AddBaseDbContextPool<InstanceRegistrationContext>();
|
|
|
|
|
services.AddBaseDbContextPool<IntegrationEventLogContext>();
|
|
|
|
|
services.AddBaseDbContextPool<FeedDbContext>();
|
|
|
|
|
services.AddBaseDbContextPool<MessagesContext>();
|
|
|
|
|
services.AddBaseDbContextPool<WebhooksDbContext>();
|
2022-08-14 22:12:59 +00:00
|
|
|
|
services.AddAutoMapper(BaseStartup.GetAutoMapperProfileAssemblies());
|
|
|
|
|
services.AddMemoryCache();
|
|
|
|
|
services.AddSingleton<IEventBus, MockEventBusRabbitMQ>();
|
|
|
|
|
services.AddCacheNotify(config);
|
|
|
|
|
|
|
|
|
|
var diHelper = new DIHelper();
|
2022-08-10 09:25:53 +00:00
|
|
|
|
diHelper.Configure(services);
|
|
|
|
|
|
2022-11-07 12:58:11 +00:00
|
|
|
|
diHelper.TryAdd<MigrationCreator>();
|
|
|
|
|
diHelper.TryAdd<MigrationRunner>();
|
|
|
|
|
|
2022-08-10 09:25:53 +00:00
|
|
|
|
});
|
|
|
|
|
|
2023-01-10 10:31:23 +00:00
|
|
|
|
if(string.IsNullOrEmpty(param.UserName) && string.IsNullOrEmpty(param.Mail))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("username or email must be entered");
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-10 09:25:53 +00:00
|
|
|
|
var app = builder.Build();
|
2022-12-23 10:49:25 +00:00
|
|
|
|
Console.WriteLine("backup start");
|
2022-11-01 09:27:29 +00:00
|
|
|
|
var migrationCreator = app.Services.GetService<MigrationCreator>();
|
2023-01-10 10:31:23 +00:00
|
|
|
|
var fileName = migrationCreator.Create(param.Tenant, param.UserName, param.Mail, param.ToRegion);
|
2022-12-23 10:49:25 +00:00
|
|
|
|
Console.WriteLine("backup was success");
|
2022-12-28 15:18:10 +00:00
|
|
|
|
Console.WriteLine("restore start");
|
|
|
|
|
var migrationRunner = app.Services.GetService<MigrationRunner>();
|
|
|
|
|
await migrationRunner.Run(fileName, param.ToRegion);
|
|
|
|
|
Console.WriteLine("restore was success");
|
2022-08-14 22:12:59 +00:00
|
|
|
|
|
2022-12-28 15:18:10 +00:00
|
|
|
|
Directory.GetFiles(AppContext.BaseDirectory).Where(f => f.Equals(fileName)).ToList().ForEach(File.Delete);
|
2022-09-05 11:27:38 +00:00
|
|
|
|
|
|
|
|
|
if (Directory.Exists(AppContext.BaseDirectory + "\\temp"))
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(AppContext.BaseDirectory + "\\temp");
|
2022-12-28 15:18:10 +00:00
|
|
|
|
}
|
2022-11-29 13:38:44 +00:00
|
|
|
|
|
2022-12-28 15:18:10 +00:00
|
|
|
|
Console.WriteLine("migration was success");
|
2022-11-30 16:03:44 +00:00
|
|
|
|
|
2022-11-29 13:38:44 +00:00
|
|
|
|
public sealed class Options
|
|
|
|
|
{
|
|
|
|
|
[Option('t', "tenant", Required = true)]
|
|
|
|
|
public int Tenant { get; set; }
|
|
|
|
|
|
2023-01-10 10:31:23 +00:00
|
|
|
|
[Option('u', "username", Required = false, HelpText = "enter username or mail for find user")]
|
2022-11-29 13:38:44 +00:00
|
|
|
|
public string UserName { get; set; }
|
|
|
|
|
|
2023-01-10 10:31:23 +00:00
|
|
|
|
[Option('m', "mail", Required = false, HelpText = "enter username or mail for find user")]
|
|
|
|
|
public string Mail { get; set; }
|
|
|
|
|
|
2022-11-29 13:38:44 +00:00
|
|
|
|
[Option("toregion", Required = true)]
|
|
|
|
|
public string ToRegion { get; set; }
|
|
|
|
|
|
|
|
|
|
[Option("fromregion", Required = false, Default = "personal")]
|
|
|
|
|
public string FromRegion { get; set; }
|
2022-09-05 11:27:38 +00:00
|
|
|
|
}
|