---
sourceDocument: Xanadu Now Platform の管理
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/xanadu/platform-administration

 Release :

    - xanadu

ft:locale :

    - ja-JP

ft:publication_title :

    - Xanadu Now Platform の管理

ft:clusterId :

    - platadm

bundleId :

    - platadm

workflow :

    - Platform


---

# 非参照フィールドから参照フィールドにテーブルデータをアーカイブするためのデータ移行プロセス

# 非参照フィールドから参照フィールドにテーブルデータをアーカイブするためのデータ移行プロセス {#ariaid-title1}

* リリースバージョン: Xanadu
* 
* 更新日 2024年08月01日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：5分

データ移行プロセスは、子孫および関連テーブルを含む既存のアーカイブテーブルからデータを移動します。このプロセスを完了する際に理解すべき特別なスクリプトと注意事項があります。

## データ移行ジョブ (RefCopyJob) {#archive-reference-migration__section_jw3_txq_vnb}

移行プロセスを行う各テーブルについて、RefCopyJob は参照フィールドの sys_id を識別し、表示値を正しい sys_id に更新します。同じタイムスタンプのレコードが 1 万件を超える場合を除き、ジョブは一度に 1 万件のレコードを設定します。移行の進行状況は、アーカイブされたタイムスタンプに依存します。スクリプトにより、移行するテーブルが決定されます。

    var tables = GlideDBObjectManager.get().getAllExtensions(current.table);
        for (i = 0; i < tables.size(); i++) {
            var gr = new GlideRecord('sys_archive_ref_migration');
            gr.addQuery('table', 'ar_' + tables.get(i));
            gr.query();
            if (!gr.next()) {
                if (GlideTableDescriptor.isValid('ar_' + tables.get(i))) {
                    var gr2 = new GlideRecord("sys_archive_ref_migration");
                    gr2.initialize();
                    gr2.setValue('rule', current.sys_id);
                    gr2.setValue('table', 'ar_' + tables.get(i));
                    gr2.setValue('reference_migration_progress', 'waiting');
                    gr2.insert();
                }
            }
        }
        //Also get insert related records tables as well
        var map = new GlideRecord('sys_archive');
        map.addQuery('table', current.table);
        map.query();
        if (map.next()) {
            var id = map.getValue('sys_id');
            if (!(id === undefined)) {
                var related = new GlideRecord('sys_archive_related');
                related.addQuery('archive_map', id);
                related.addQuery('action', 'archive');
                related.query();
                while (related.next()) {
                    if (!GlideTableDescriptor.isValid('ar_' + related.getValue('table'))) {
                        gs.log('Related Record table: ' + related.getValue('table') + ' not created yet');
                        continue;
                    }
     
                    var gr3 = new GlideRecord("sys_archive_ref_migration");
                    gr3.initialize();
                    gr3.setValue('rule', current.sys_id);
                    gr3.setValue('table', 'ar_' + related.getValue('table'));
                    gr3.setValue('reference_migration_progress', 'waiting');
                    gr3.insert();
                }
            }
        }

## 移行されたテーブルの sys_dictionary タイプを変更するジョブ (ArchiveRefJob) {#archive-reference-migration__section_mld_fcr_vnb}

アーカイブルールに関連付けられたテーブルが完全に移行された後、ArchiveRefJob ジョブが実行されます。このジョブは、アーカイブテーブルの sys_dictionary タイプを文字列から参照に変更します。

## RefCopyJob および ArchiveRefJob のノードエラーの修正 {#archive-reference-migration__section_mv3_bdr_vnb}

これらのジョブの実行中にノード障害が発生すると、データ移行のステータスが不適切な状態のままになります。RefCopyJob が失敗した場合、テーブルが移行ステータスのままになる可能性があります。この条件は、sys_archive_ref_migration 内の行が非常に長い時間 (数値化？) \[移行中\] ステータスでスタックしていないかどうかで確認できます。特定の行のステータスを \[移行中\] から \[待機中\] に更新し、ジョブが再度実行されたときに RefCopyJob がテーブルのデータ移行を続行します。  
ArchiveRefJob が途中で終了すると、ノードにも障害が発生する可能性があります。テーブルに参照フィールドであるフィールドと、まだ文字列タイプのフィールドがあるかどうかを確認します。フィールドタイプの変更中にジョブが停止した可能性があります。この条件を解決するには、プロセスを再度開始するための、バックグラウンドスクリプトで実行するトリガージョブを設定します。

    GlideRecord trigger = new GlideRecord('sys_trigger');
    trigger.initialize();
    trigger.setValue('state', 0);
    trigger.setValue('trigger_type', 0);
    trigger.setValue('next_action', new GlideDateTime());
    trigger.setValue('job_context', 'fcRuleId=' + ruleId);
    trigger.setValue('name', 'Job Reference Migration' + ' Node - ' + new GlideClusterSynchronizer().getSystemID());
    trigger.setValue('trigger_class', 'com.glide.db.auxiliary.job.ArchiveRefJob');
    trigger.insert();


