コード例 #1
0
        public async Task <int> RunAsync()
        {
            // get the mysql connection
            Console.WriteLine("Attempting connection to database...");
            using (var connection = GetDatabaseConnection())
            {
                await connection.OpenAsync();

                Console.WriteLine("Connected to database...");
                Console.WriteLine("Fetching database names to backup...");
                var databaseNames = GetDatabaseNames(connection);

                foreach (var databaseName in databaseNames)
                {
                    if (backupOptions.Databases != "*")
                    {
                        var databasesToBackup = backupOptions.Databases.Split(',');
                        if (!databasesToBackup.Any(t => t.Equals(databaseName, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            Console.WriteLine($"Skipping {databaseName} not part of {backupOptions.Databases}");
                            continue;
                        }
                    }

                    Console.WriteLine($"Currently on database {databaseName}");
                    await BackupUsingMysqlDump(databaseName);
                }
            }

            if (this.backupOptions.NotifySuccess)
            {
                await notifyService.SendNotification("Backup Success", $"The backup of the server {GetHostName(this.mySqlOptions)} is successful.", facts : new System.Collections.Generic.Dictionary <string, string>
                {
                    { "Completed At", $"{DateTimeOffset.UtcNow}" }
                });
            }

            return(0);
        }