Beispiel #1
0
        private async Task <string> _ValidateRunAsync(int i)
        {
            var file = this.Files.ElementAtOrDefault(i);

            // Write Log
            string t = FormatCli.H2($"Task: { (i + 1).ToString() }");

            t += FormatCli.KeyValue("File", file.File);
            t += FormatCli.KeyValue("Checksum", file.Checksum);

            //Checks
            var path = DirFile.Combine(this.AppSettings.Path.Export, file.File);

            if (!System.IO.File.Exists(path))
            {
                t += Environment.NewLine;
                t += $"Error: Could not find file {path}";
                return(t);
            }

            var checksum = await Task.Run(() => FilesModel.Hash(path));

            if (checksum != file.Checksum)
            {
                t += Environment.NewLine;
                t += $"Error: Checksum is not identical, backup maybe corrupted!";
                return(t);
            }

            t += FormatCli.KeyValue("Status", "Valid!");

            return(t);
        }
Beispiel #2
0
        private async Task <string> _ImportRunTaskAsync(int i)
        {
            var file = this.Files.ElementAtOrDefault(i);

            // Write Log
            string t = FormatCli.H2($"Task: { (i + 1).ToString() }");

            t += FormatCli.KeyValue("File", file.File);
            t += FormatCli.KeyValue("Checksum", file.Checksum);

            //Checks
            var path = DirFile.Combine(this.AppSettings.Path.Export, file.File);

            if (!System.IO.File.Exists(path))
            {
                t += Environment.NewLine;
                t += $"Error: Could not find file {path}";
                return(t);
            }
            this.Import.File = path;

            // Validate
            if (this.Import.SkipValidation)
            {
                t += FormatCli.KeyValue("Status", "Skipped!");
            }
            else
            {
                var checksum = await Task.Run(() => FilesModel.Hash(path));

                if (checksum != file.Checksum)
                {
                    t += Environment.NewLine;
                    t += $"Error: Checksum is not identical, backup maybe corrupted!";
                    return(t);
                }

                t += FormatCli.KeyValue("Status", "Valid!");
            }

            // Decompress
            var decompress = await this.Import.DecompressAsync();

            // Import
            var task = await this.Import.RunAsync(this.Connect, this.Output);

            task.Duartion.Add(decompress.Duartion);

            t += FormatCli.KeyValue("Duration", task.Duartion.TotalMinutes + " min");
            if (this.Import.Config.Verbose)
            {
                t += FormatCli.H3("Parameter");
                var connector = this.Import.Config.Format == "p" ? new Connectors.Psql(AppSettings).BinName : this.Import.BinName;
                t += $"{ connector } { this.Import.GetPatameters(this.Connect) }" + Environment.NewLine;
            }

            if (!string.IsNullOrEmpty(task.Ouput))
            {
                t += FormatCli.H3("Output:");
                t += task.Ouput;
            }

            if (!string.IsNullOrEmpty(task.Error))
            {
                t += FormatCli.H3("Error:");
                t += task.Error;
            }

            return(t);
        }
Beispiel #3
0
        private async Task <string> _ExportRunTaskAsync(int i)
        {
            var path = System.IO.Path.GetDirectoryName(this.Export.File);

            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }

            // ExportRunAsync
            var task = await this.Export.RunAsync(this.Connect, this.Output);

            // Compress export
            var compress = await this.Export.CompressAsync();

            task.Duartion.Add(compress.Duartion);

            // Add to files
            var exported = new FilesModel(this.Export.File, task);

            this.Files.Add(exported);

            // Write log JSON
            if (this.Tasks == 1 || this.Tasks == i + 1)
            {
                var logName = this.Export.File;
                if (this.Tasks != 1)
                {
                    logName = this.Export.File.Replace(this.Export.Tables.Last(), "export");
                }

                this.Import.Config = new PgConfig.PgRestoreModel(this.Export.Config);
                this.JobSave(logName + ".json");
            }

            // Write Log
            string t = FormatCli.H2($"Task: { (i + 1).ToString() }");

            t += FormatCli.KeyValue("File", this.Export.FileName);
            t += FormatCli.KeyValue("Duration", task.Duartion.TotalMinutes + " min");
            t += FormatCli.KeyValue("Checksum", exported.Checksum);
            if (this.Export.Config.Verbose)
            {
                t += FormatCli.H3("Parameter");
                t += $"{ this.Export.BinName } { this.Export.GetPatameters(this.Connect) }" + Environment.NewLine;
            }

            if (!string.IsNullOrEmpty(task.Ouput))
            {
                t += FormatCli.H3("Output:");
                t += task.Ouput;
            }

            if (!string.IsNullOrEmpty(task.Error))
            {
                t += FormatCli.H3("Error:");
                t += task.Error;
            }

            this.ExportTaskPrepare();

            return(t);
        }