diff --git a/api/Sozsoft.Platform.HttpApi.Host.Dockerfile b/api/Sozsoft.Platform.HttpApi.Host.Dockerfile index bf9a2b1..8b291e3 100644 --- a/api/Sozsoft.Platform.HttpApi.Host.Dockerfile +++ b/api/Sozsoft.Platform.HttpApi.Host.Dockerfile @@ -75,6 +75,7 @@ RUN mkdir -p $HOME/.config/DevExpress && \ # fontconfig ve fonts-* DevExpress reporting için gerekli RUN apk update RUN apk add --no-cache \ + tzdata \ icu-data-full \ icu-libs \ libgdiplus \ diff --git a/api/src/Sozsoft.Platform.Application/BackgroundWorker/BackgroundWorkerInitializer.cs b/api/src/Sozsoft.Platform.Application/BackgroundWorker/BackgroundWorkerInitializer.cs index a12da0a..4a21f10 100644 --- a/api/src/Sozsoft.Platform.Application/BackgroundWorker/BackgroundWorkerInitializer.cs +++ b/api/src/Sozsoft.Platform.Application/BackgroundWorker/BackgroundWorkerInitializer.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.InteropServices; using System.Text.Json; using System.Threading.Tasks; using Hangfire; @@ -31,6 +32,12 @@ public class BackgroundWorkerInitializer : ITransientDependency public async Task RunAsync() { + var turkeyTimeZone = GetTurkeyTimeZone(); + + _logger.LogInformation( + "Background workers Türkiye saat dilimine göre kuruluyor. TimeZoneId: {TimeZoneId}", + turkeyTimeZone.Id); + var jobs = JobStorage.Current.GetConnection().GetRecurringJobs(); var workers = await _repo.GetListAsync(a => a.IsActive); @@ -53,7 +60,7 @@ public class BackgroundWorkerInitializer : ITransientDependency worker.Cron, new RecurringJobOptions { - TimeZone = TimeZoneInfo.Local, + TimeZone = turkeyTimeZone }); if (worker.WorkerType == WorkerTypeEnum.MailQueueWorker && !worker.Options.IsNullOrWhiteSpace()) @@ -67,4 +74,28 @@ public class BackgroundWorkerInitializer : ITransientDependency } } } -} + + private static TimeZoneInfo GetTurkeyTimeZone() + { + var timeZoneIds = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) + ? new[] { "Turkey Standard Time", "Europe/Istanbul" } + : new[] { "Europe/Istanbul", "Turkey Standard Time" }; + + foreach (var timeZoneId in timeZoneIds) + { + try + { + return TimeZoneInfo.FindSystemTimeZoneById(timeZoneId); + } + catch (TimeZoneNotFoundException) + { + } + catch (InvalidTimeZoneException) + { + } + } + + throw new TimeZoneNotFoundException( + "Türkiye saat dilimi bulunamadı. Linux/Docker için 'Europe/Istanbul', Windows için 'Turkey Standard Time' gerekir."); + } +} \ No newline at end of file diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/HostData.json b/api/src/Sozsoft.Platform.DbMigrator/Seeds/HostData.json index 44be831..3b21d70 100644 --- a/api/src/Sozsoft.Platform.DbMigrator/Seeds/HostData.json +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/HostData.json @@ -1073,7 +1073,8 @@ "workerType": "BackupWorker", "isActive": true, "dataSourceCode": "Default", - "beforeSp": "Adm_T_DatabaseBackup" + "beforeSp": "Adm_T_DatabaseBackupAll", + "afterSp": "Adm_T_DatabaseBackupDeleteAll" } ], "ContactTitles": [ diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackup.sql b/api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackupAll.sql similarity index 58% rename from api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackup.sql rename to api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackupAll.sql index d1ef0fa..2746b29 100644 --- a/api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackup.sql +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackupAll.sql @@ -1,14 +1,15 @@ -CREATE OR ALTER PROCEDURE [dbo].[Adm_T_DatabaseBackup] +CREATE OR ALTER PROCEDURE [dbo].[Adm_T_DatabaseBackupAll] AS BEGIN SET NOCOUNT ON; DECLARE @SQL NVARCHAR(MAX) = N''; - + DECLARE @Tarih NVARCHAR(20) = CONVERT(CHAR(8), CAST(SYSUTCDATETIME() AT TIME ZONE 'UTC' AT TIME ZONE 'Turkey Standard Time' AS DATE),112); + SELECT @SQL = @SQL + N' BACKUP DATABASE ' + QUOTENAME(name) + N' TO DISK = N''/var/opt/mssql/backup/' -+ name + N'_' + CONVERT(VARCHAR(8), GETDATE(), 112) + N'.bak'' ++ name + N'_' + @Tarih + N'.bak'' WITH INIT;' FROM sys.databases WHERE name NOT IN ('master','model','msdb','tempdb') diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackupDeleteAll.sql b/api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackupDeleteAll.sql new file mode 100644 index 0000000..69429db --- /dev/null +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackupDeleteAll.sql @@ -0,0 +1,11 @@ +CREATE OR ALTER PROCEDURE [dbo].[Adm_T_DatabaseBackupDeleteAll] +AS +BEGIN + SET NOCOUNT ON; + + DECLARE @DeleteDate date + + SET @DeleteDate = DATEADD(DAY, -1, GETDATE()) + + EXEC master.sys.xp_delete_file 0, '/var/opt/mssql/backup/', 'BAK', @DeleteDate, 0; +END \ No newline at end of file