DBMoto APIを使用することで、GUIツールであるDBMoto Management Centerからの操作ではなく、バッチを実行することで外部からDBMotoの操作を制御することが可能です。
ここではDBMotoのレプリケーションジョブやグループジョブを外部から制御するプログラムをご紹介します。
これらを使用することで、任意のタイミングでジョブを実行・停止したり、他アプリケーションとの連携が可能となります。
●レプリケーションを有効化・無効化するサンプルC#プログラム
using System;
using System.Collections.Generic;
using System.Text;
using HiTSoftware.DBMoto.Application;
using HiTSoftware.DBMoto.ObjectModel;
namespace APISamples
{
    public class SampleReplicationAsynch
    {
        public static void Main()
        {
            DBMotoApplication dbmApp = null;
            IServer dbmServer = null;
            IMetadata currentMetadata = null;
            try
            {
                // 初期設定、サーバ接続
                dbmApp = DBMotoApplication.Instance;
                dbmServer = dbmApp.Servers["local"];
                dbmServer.Connect();
                // カレントメタデータのロード
                currentMetadata = dbmServer.Metadatas.DefaultMetadata;
                currentMetadata.Load(true);
                // レプリケーション名
                IReplication repl = currentMetadata.Replications["Replication"];
                // レプリケーション有効化
                if (repl.ReplStatus == ReplStatus.Disabled)
                    repl.AsynchEnable();
                // 待機
                System.Threading.Thread.Sleep(3000);
                // レプリケーション無効化
                if (repl.ReplStatus != ReplStatus.Disabled)
                    repl.AsynchDisable();
                // 待機
                System.Threading.Thread.Sleep(3000);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (currentMetadata != null)
                    currentMetadata.Unload();
                if (dbmServer != null)
                    dbmServer.Disconnect();
                if (dbmApp != null)
                    dbmApp.Dispose();
            }
        }
    }
}
●グループを有効化・無効化するサンプルC#プログラム
using System;
using System.Collections.Generic;
using System.Text;
using HiTSoftware.DBMoto.Application;
using HiTSoftware.DBMoto.ObjectModel;
namespace APISamples
{
    public class SampleGroupAsynch
    {
        public static void Main()
        {
            DBMotoApplication dbmApp = null;
            IServer dbmServer = null;
            IMetadata currentMetadata = null;
            try
            {
                // 初期設定、サーバ接続
                dbmApp = DBMotoApplication.Instance;
                dbmServer = dbmApp.Servers["local"];
                dbmServer.Connect();
                // カレントメタデータのロード
                currentMetadata = dbmServer.Metadatas.DefaultMetadata;
                currentMetadata.Load(true);
                // グループ名
                IGroup group = currentMetadata.Groups["Group"];
                // グループ有効化
                if (group.ReplStatus == ReplStatus.Disabled)
                    group.AsynchEnable();
                // 待機
                System.Threading.Thread.Sleep(3000);
                // グループ無効化
                if (group.ReplStatus != ReplStatus.Disabled)
                    group.AsynchDisable();
                // 待機
                System.Threading.Thread.Sleep(3000);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (currentMetadata != null)
                    currentMetadata.Unload();
                if (dbmServer != null)
                    dbmServer.Disconnect();
                if (dbmApp != null)
                    dbmApp.Dispose();
            }
        }
    }
}
関連したトピックス
- APIからリフレッシュを実行するサンプルスクリプト[C#] [Syniti DR (DBMoto)]
- APIからレプリケーションの最新の実行件数を取得するサンプルスクリプト[C#] [Syniti DR (DBMoto)]
- APIからレプリケーション結果の検証やデータ整合を実行するサンプルスクリプト[C#] [Syniti DR (DBMoto)]
- DBMotoが使うスレッド数の算出方法【リアルタイムレプリケーションツールDBMoto】
- Syniti Data Replication (旧DBMoto)でのスクリプトの書き方④:レプリケーションスクリプト
- Syniti Data Replication (旧DBMoto)でのスクリプトの書き方③:グローバルスクリプト用の関数とイベント
- 2つのソーステーブルからターゲットの一つのレコードにレプリケーション
- レプリケーションの際にnullを特定の値に変換する方法 その1【リアルタイムレプリケーションツールDBMoto】
- MySQLへのレプリケーションで “Loading local data is disabled” エラーとなる場合の対処法
- ジュリアンデートのレプリケーション【リアルタイムレプリケーションツールDBMoto】
 
					


 RSSフィードを取得する
 RSSフィードを取得する 
	 
	 
	