コード例 #1
0
            public void RunJob()
            {
                var filename = Path.Combine(tmpfolder, Id + ".tbm");

                try
                {
                    if (!Directory.Exists(tmpfolder))
                    {
                        Directory.CreateDirectory(tmpfolder);
                    }

                    var backuper = new BackupManager(filename, currentWebConfigPath);
                    backuper.ProgressChanged += (o, e) =>
                    {
                        Percentage = Math.Max(0, Math.Min((int)e.Progress / 2, 50));
                    };

                    backuper.Save(Tenant);

                    using (var stream = new FileStream(filename, FileMode.Open))
                        using (var progressStream = new ProgressStream(stream))
                        {
                            progressStream.OnReadProgress += (o, e) =>
                            {
                                Percentage = Math.Max(0, Math.Min(100, 50 + e / 2));
                            };

                            var uploadname = string.Format("{0}-{1:yyyyMMdd-HHmmss}.zip", CoreContext.TenantManager.GetTenant(Tenant).TenantDomain, DateTime.UtcNow).ToLowerInvariant();
                            ExpireDate = DateTime.UtcNow.Add(expire);
                            Status     = GetStore().SavePrivate(string.Empty, uploadname, progressStream, ExpireDate);
                        }

                    IsCompleted = true;
                    Percentage  = 100;

                    NotifyHelper.SendAboutBackupCompleted(Tenant, userId, (string)Status, ExpireDate);
                }
                catch (Exception e)
                {
                    Error = e;
                    log.Error(e);
                }
                finally
                {
                    try
                    {
                        if (File.Exists(filename))
                        {
                            File.Delete(filename);
                        }
                    }
                    catch (Exception e)
                    {
                        log.Error(e);
                    }
                }
            }
コード例 #2
0
        protected override void RunInternal()
        {
            var config          = BackupConfigurationSection.GetSection();
            var pathToWebConfig = FileUtility.GetRootedPath(config.WebConfigs.GetCurrentConfig());
            var tempFolderPath  = FileUtility.GetRootedPath(config.TempFolder);

            if (!pathToWebConfig.EndsWith(".config", StringComparison.InvariantCultureIgnoreCase))
            {
                pathToWebConfig = Path.Combine(pathToWebConfig, "web.config");
            }

            if (!Directory.Exists(tempFolderPath))
            {
                Directory.CreateDirectory(tempFolderPath);
            }

            var backupFile = CreateBackupFilePath(tempFolderPath);

            try
            {
                var backuper = new BackupManager(backupFile, pathToWebConfig);
                backuper.ProgressChanged += (sender, args) =>
                {
                    if (args.Progress > 0)
                    {
                        Progress = Math.Max(0, Math.Min((int)args.Progress / 2, 50));
                    }
                };

                backuper.Save(TenantId);

                using (var stream = new FileStream(backupFile, FileMode.Open))
                    using (var progressStream = new ProgressStream(stream))
                    {
                        progressStream.OnReadProgress += (sender, args) =>
                        {
                            Progress = Math.Max(0, Math.Min(100, 50 + args / 2));
                        };

                        ExpirationDate = DateTime.UtcNow + config.ExpirePeriod;

                        var storage = StorageFactory.GetStorage(pathToWebConfig, "backupfiles", "backup");
                        Link = storage.SavePrivate(string.Empty, Path.GetFileName(backupFile), progressStream, ExpirationDate);
                    }

                NotifyHelper.SendAboutBackupCompleted(TenantId, notificationReceiverId, Link, ExpirationDate);
            }
            finally
            {
                File.Delete(backupFile);
            }
        }
コード例 #3
0
            public void RunJob()
            {
                if (ThreadPriority.BelowNormal < Thread.CurrentThread.Priority)
                {
                    Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
                }

                var backupName = string.Format("{0}_{1:yyyy-MM-dd_HH-mm-ss}.{2}", CoreContext.TenantManager.GetTenant(TenantId).TenantAlias, DateTime.UtcNow, ArchiveFormat);
                var tempFile   = Path.Combine(tempFolder, backupName);

                try
                {
                    var backupTask = new BackupPortalTask(Log, TenantId, configPaths[currentRegion], tempFile);
                    if (!BackupMail)
                    {
                        backupTask.IgnoreModule(ModuleName.Mail);
                    }
                    backupTask.IgnoreTable("tenants_tariff");
                    backupTask.ProgressChanged += (sender, args) => Percentage = 0.9 * args.Progress;
                    backupTask.RunJob();

                    var backupStorage = BackupStorageFactory.GetBackupStorage(StorageType, TenantId);
                    var storagePath   = backupStorage.Upload(StorageBasePath, tempFile, UserId);
                    Link = backupStorage.GetPublicLink(storagePath);

                    var repo = BackupStorageFactory.GetBackupRepository();
                    repo.SaveBackupRecord(
                        new BackupRecord
                    {
                        Id              = (Guid)Id,
                        TenantId        = TenantId,
                        IsScheduled     = IsScheduled,
                        FileName        = Path.GetFileName(tempFile),
                        StorageType     = StorageType,
                        StorageBasePath = StorageBasePath,
                        StoragePath     = storagePath,
                        CreatedOn       = DateTime.UtcNow,
                        ExpiresOn       = StorageType == BackupStorageType.DataStore ? DateTime.UtcNow.AddDays(1) : DateTime.MinValue
                    });

                    Percentage = 100;

                    if (UserId != Guid.Empty && !IsScheduled)
                    {
                        NotifyHelper.SendAboutBackupCompleted(TenantId, UserId, Link);
                    }

                    IsCompleted = true;
                }
                catch (Exception error)
                {
                    Log.Error("RunJob - Params: {0}, Error = {1}", new { Id = Id, Tenant = TenantId, File = tempFile, BasePath = StorageBasePath, }, error);
                    Error       = error;
                    IsCompleted = true;
                }
                finally
                {
                    try
                    {
                        File.Delete(tempFile);
                    }
                    catch (Exception error)
                    {
                        Log.Error("can't delete file: {0}", error);
                    }
                }
            }