Ejemplo n.º 1
0
        private static BackupProgress ToBackupProgress(IProgressItem progressItem)
        {
            if (progressItem == null)
            {
                return(null);
            }

            var progress = new BackupProgress
            {
                IsCompleted = progressItem.IsCompleted,
                Progress    = (int)progressItem.Percentage,
                Error       = progressItem.Error != null ? ((Exception)progressItem.Error).Message : null
            };

            var backupProgressItem = progressItem as BackupProgressItem;

            if (backupProgressItem != null)
            {
                progress.Link = backupProgressItem.Link;
            }
            else
            {
                var transferProgressItem = progressItem as TransferProgressItem;
                if (transferProgressItem != null)
                {
                    progress.Link = transferProgressItem.Link;
                }
            }

            return(progress);
        }
        /// <summary>
        /// Sends the backup progress status to the messaging provider for delivery.
        /// </summary>
        /// <param name="Progress">An initialized <c>BackupProgress</c> object.</param>
        public async Task SendBackupProgressStatusMessageAsync(BackupProgress Progress)
        {
            var finalMessage = string.Format(MessageFormat,
                                             Environment.MachineName.ToUpper(), Progress.OverallPercentage,
                                             Progress.BackedUpFileCount, Progress.BackedUpFileSize,
                                             Progress.RemainingFileCount, Progress.RemainingFileSize);

            Logger.WriteTraceMessage("Sending backup status update messages through Twilio.");

            foreach (var destPhone in DestinationPhones)
            {
                try
                {
                    var message = await MessageResource.CreateAsync(
                        body : finalMessage,
                        from : new PhoneNumber(SourcePhone),
                        to : new PhoneNumber(destPhone)
                        ).ConfigureAwait(false);

                    Logger.WriteTraceMessage(string.Format("Twilio message {0} delivery attempt result: {1}", message.Sid, message.Status));
                }
                catch (ApiException ex)
                {
                    Logger.WriteTraceError("Failed to send an SMS message through Twilio.", ex, Logger.GenerateFullContextStackTrace());
                }
            }
        }
Ejemplo n.º 3
0
        public bool PerformBackup()
        {
            string backupDirectory = HostingEnvironment.MapPath(this.PostgreSQL.DatabaseBackupDirectory);

            if (backupDirectory == null)
            {
                this.OnOnBackupFail(new BackupProgressInfo(Warnings.BackupDirectoryNotFound));
                return(false);
            }

            backupDirectory = Path.Combine(backupDirectory, this.FileName);
            string path = Path.Combine(backupDirectory, "db.backup");

            Directory.CreateDirectory(backupDirectory);


            BackupProcess process = new BackupProcess(this.PostgreSQL, path);

            process.Progress += delegate(BackupProgressInfo info)
            {
                BackupProgress progress = this.Progress;

                if (progress != null)
                {
                    progress(new BackupProgressInfo(info.Message));
                }
            };

            process.BackupComplete += delegate(object sender, EventArgs args)
            {
                BackupResource resourceBackup = new BackupResource(backupDirectory);
                resourceBackup.Backup();

                BackupCompression compression = new BackupCompression(backupDirectory);
                compression.Compress(true);

                BackupComplete complete = this.BackupComplete;

                if (complete != null)
                {
                    complete(this, args);
                }
            };

            bool result = process.Execute();

            if (!result)
            {
                this.OnOnBackupFail(new BackupProgressInfo(Warnings.CannotCreateABackup));
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        private void Data_Received(object sender, DataReceivedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(e.Data))
            {
                BackupProgress progress = this.Progress;

                if (progress != null)
                {
                    progress(new BackupProgressInfo(e.Data));
                }
            }
        }
Ejemplo n.º 5
0
        public async Task <BackupDirResult> Dump(string sourceDir, string backupDir)
        {
            _progress = new BackupProgress();
            _logger?.LogInformation($"Dump directory: '{sourceDir}' into '{backupDir}'");
            await Connect();
            await EnsureBackupDirectory(backupDir);

            var result = await DumpSourceDir(sourceDir, backupDir);

            await Disconnect();

            return(result);
        }
Ejemplo n.º 6
0
        private BackupProgress ToBackupProgress(BaseBackupProgressItem progressItem)
        {
            if (progressItem == null)
            {
                return(null);
            }
            var progress = new BackupProgress
            {
                IsCompleted        = progressItem.IsCompleted,
                Progress           = (int)progressItem.Percentage,
                Error              = progressItem.Error != null ? ((Exception)progressItem.Error).Message : "",
                TenantId           = progressItem.TenantId,
                BackupProgressEnum = progressItem.BackupProgressItemEnum.Convert()
            };

            if (progressItem is BackupProgressItem backupProgressItem && backupProgressItem.Link != null)
            {
                progress.Link = backupProgressItem.Link;
            }
Ejemplo n.º 7
0
        /// <summary>
        /// Sends the status update to the current status provider.
        /// </summary>
        private async Task SendStatusUpdateAsync(BackupProgress Progress)
        {
            if (MessagingConnections.Count == 0)
            {
                Logger.WriteTraceWarning("Unable to send status updates. There are no messaging providers configured/enabled.");
                return;
            }

            foreach (var messageProvider in MessagingConnections)
            {
                Logger.WriteTraceMessage("Attempting to send status update for messaging provider: " + messageProvider.Key);

                try
                {
                    await messageProvider.Value.SendBackupProgressStatusMessageAsync(Progress).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    Logger.WriteTraceError("Failed to send a backup progress update message: " + ex.ToString());
                }
            }
        }