Direkt zum Inhalt

Wie verwende ich die AWS-CLI und jq, um eine Sicherungskopie meiner AWS-DMS-Aufgabeneinstellungen zu erstellen?

Lesedauer: 4 Minute
0

Ich möchte die Einstellungen meiner AWS Database Migration Service (AWS DMS)-Replikationsaufgaben sichern, um sie zu einem späteren Zeitpunkt wiederherzustellen oder als Vorlage zu verwenden.

Behebung

Hinweis: Wenn du beim Ausführen von AWS Command Line Interface (AWS CLI)-Befehlen Fehlermeldungen erhältst, findest du weitere Informationen dazu unter Problembehandlung bei der AWS CLI. Stelle außerdem sicher, dass du die neueste Version der AWS CLI verwendest.

Verwende die AWS-CLI und den JQ-Befehlszeilen-JSON-Prozessor, um ein Backup der Einstellungen für die AWS-DMS-Replikationsaufgabe zu erstellen.

Abrufen der Replikationsaufgaben-Einstellungen

Um die Replikationsaufgaben-Einstellungen für AWS DMS abzurufen, führe den AWS CLI-Befehl describe-replication-tasks aus. Verwende das Flag --filters, um nur die Aufgabe zurückzugeben, die einem der folgenden Elemente entspricht:

  • Der ID der Replikationsaufgabe
  • Dem Amazon-Ressourcennamen (ARN) der Replikationsaufgabe

Um die Einstellungen für die Replikationsaufgabe für die AWS DMS-Aufgabe mit der Replikationsaufgaben-ID abzurufen, führe den folgenden Befehl describe-replication-tasks aus:

aws dms describe-replication-tasks --filter Name=replication-task-id,Values=dms_task_id --output json

Hinweis: Ersetze dms_task_id durch die ID der AWS-DMS-Replikationsaufgabe.

Um die Replikationsaufgaben-Einstellungen für die AWS-DMS-Aufgabe mit dem ARN der Replikationsaufgabe abzurufen, führe den folgenden Befehl aus:

aws dms describe-replication-tasks --filter Name=replication-task-arn,Values=dms_task_arn --output json

Hinweis: Ersetze dms_task_arn durch den ARN für die AWS-DMS-Replikationsaufgabe.

Die JSON-Ausgabe mit jq filtern und transformieren

Hinweis: Informationen zum Herunterladen des jq-Tool findest du unter./jq auf der jqlang-Website.

Du musst die JSON-Einstellungen für die Replikationsaufgabe filtern und transformieren, um sie für die Wiederherstellung zu einem späteren Zeitpunkt kompatibel zu machen.

Verwende den jq-Befehlszeilen-JSON-Prozessor, um das Ausgabe-JSON je nach Art der ausgeführten Aufgabe zu ändern.

Entferne Aufgabe des vollständigen Ladens die folgenden Daten:

  • ReplicationTaskArn
  • ReplicationTaskStartDate
  • ReplicationTaskStats
  • Status
  • StopReason
  • ReplicationTaskCreationDate
  • CloudWatchLogGroup
  • CloudWatchLogStream
  • RecoveryCheckpoint

Füge für eine Change Data Capture (CDC)-Aufgabe den CdcStartPosition-Schlüssel hinzu und lege den Wert dann auf RecoveryCheckpoint fest. Entferne außerdem die folgenden Daten:

  • ReplicationTaskArn
  • ReplicationTaskStartDate
  • ReplicationTaskStats
  • Status
  • StopReason
  • ReplicationTaskCreationDate
  • CloudWatchLogGroup
  • CloudWatchLogStream
  • RecoveryCheckpoint

Entferne für eine Aufgabe des vollständigen Ladens und eine CDC-Aufgabe die folgenden Daten:

  • ReplicationTaskArn
  • ReplicationTaskStartDate
  • ReplicationTaskStats
  • Status
  • StopReason
  • ReplicationTaskCreationDate
  • CloudWatchLogGroup
  • CloudWatchLogStream
  • RecoveryCheckpoint

Um die JSON-Ausgabe an jq zu senden und dann die Daten der Replikationsaufgabe zu filtern und zu transformieren, führe einen der folgenden describe-replication-tasks-Befehle aus.

Führe den folgenden Befehl aus, um die AWS-DMS-Replikationsaufgaben-ID zu verwenden:

aws dms describe-replication-tasks --filter Name=replication-task-id,Values=dms_task_id --output json | jq '.ReplicationTasks | .[] | .TableMappings |= fromjson | .ReplicationTaskSettings |= fromjson | .["CdcStartPosition"] = .RecoveryCheckpoint | delpaths([    ["ReplicationTaskArn"],["ReplicationTaskStartDate"],["ReplicationTaskStats"],["Status"],["StopReason"],["ReplicationTaskCreationDate"],["ReplicationTaskSettings","Logging","CloudWatchLogGroup"],["ReplicationTaskSettings","Logging","CloudWatchLogStream"],["RecoveryCheckpoint"]])    | .TableMappings |= tostring |.ReplicationTaskSettings |= tostring'

Hinweis: Ersetze dms_task_id durch die ID der AWS-DMS-Replikationsaufgabe.

Führe den folgenden Befehl aus, um den ARN der AWS DMS-Replikationsaufgabe zu verwenden:

aws dms describe-replication-tasks --filter Name=replication-task-arn,Values=dms-task-arn --output json | jq '.ReplicationTasks | .[] | .TableMappings |= fromjson | .ReplicationTaskSettings |= fromjson | .["CdcStartPosition"] = .RecoveryCheckpoint | delpaths([    ["ReplicationTaskArn"],["ReplicationTaskStartDate"],["ReplicationTaskStats"],["Status"],["StopReason"],["ReplicationTaskCreationDate"],["ReplicationTaskSettings","Logging","CloudWatchLogGroup"],["ReplicationTaskSettings","Logging","CloudWatchLogStream"],["RecoveryCheckpoint"]])    | .TableMappings |= tostring |.ReplicationTaskSettings |= tostring'

Hinweis: Ersetze dms_task_arn durch den ARN für die AWS-DMS-Replikationsaufgabe.

Speichern der Ausgabe in einer JSON-Datei

Um die Ausgabe als Backup zu speichern, leite sie in eine JSON-Datei um. Der folgende Befehl speichert beispielsweise die Aufgabeneinstellungen für eine AWS-DMS-Aufgabe mit der dms_original_task-Aufgaben-ID in einer JSON-Datei namens task_backup.json:

aws dms describe-replication-tasks --filter Name=replication-task-id,Values=original-dms-task --output json | jq '.ReplicationTasks | .[] | .TableMappings |= fromjson | .ReplicationTaskSettings |= fromjson | .["CdcStartPosition"] = .RecoveryCheckpoint | delpaths([ ["ReplicationTaskArn"],["ReplicationTaskStartDate"],["ReplicationTaskStats"],["Status"],["StopReason"],["ReplicationTaskCreationDate"],["ReplicationTaskSettings","Logging","CloudWatchLogGroup"],["ReplicationTaskSettings","Logging","CloudWatchLogStream"],["RecoveryCheckpoint"]]) | .TableMappings |= tostring |.ReplicationTaskSettings |= tostring' > task_backup.json

Beispiel für eine JSON-Ausgabedatei:


{ "ReplicationTaskIdentifier": "original-dms-task",  "SourceEndpointArn": "arn:aws:dms:us-east-1:xxxxxxxxxxxx:endpoint:QKMQN2TCULCPYIK3CMGF2CRDC5DIWZ433BCKHZY",
  "TargetEndpointArn": "arn:aws:dms:us-east-1:xxxxxxxxxxxx:endpoint:6LEFAZCDPQD2HWHJIXJYUU4PGMTKA2AKKFN4KCA",
  "ReplicationInstanceArn": "arn:aws:dms:us-east-1:xxxxxxxxxxxx:rep:C4CAB7ANKQU2AU7WFH4BYCJSLPS3YYUGCTHL3UA",
  "MigrationType": "full-load-and-cdc",
  "TableMappings": "{\"rules\":[{\"rule-type\":\"selection\",\"rule-id\":\"293111713\",\"rule-name\":\"293111713\",\"object-locator\":{\"schema-name\":\"%\",\"table-name\":\"%\"},\"rule-action\":\"include\",\"filters\":[]}]}",
  "ReplicationTaskSettings": "{\"Logging\":{\"EnableLogging\":true,\"LogComponents\":[{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"TRANSFORMATION\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"SOURCE_UNLOAD\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"IO\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"TARGET_LOAD\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"PERFORMANCE\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"SOURCE_CAPTURE\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"SORTER\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"REST_SERVER\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"VALIDATOR_EXT\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"TARGET_APPLY\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"TASK_MANAGER\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"TABLES_MANAGER\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"METADATA_MANAGER\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"FILE_FACTORY\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"COMMON\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"ADDONS\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"DATA_STRUCTURE\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"COMMUNICATION\"},{\"Severity\":\"LOGGER_SEVERITY_DEFAULT\",\"Id\":\"FILE_TRANSFER\"}]},\"StreamBufferSettings\":{\"StreamBufferCount\":3,\"CtrlStreamBufferSizeInMB\":5,\"StreamBufferSizeInMB\":8},\"ErrorBehavior\":{\"FailOnNoTablesCaptured\":true,\"ApplyErrorUpdatePolicy\":\"LOG_ERROR\",\"FailOnTransactionConsistencyBreached\":false,\"RecoverableErrorThrottlingMax\":1800,\"DataErrorEscalationPolicy\":\"SUSPEND_TABLE\",\"ApplyErrorEscalationCount\":0,\"RecoverableErrorStopRetryAfterThrottlingMax\":true,\"RecoverableErrorThrottling\":true,\"ApplyErrorFailOnTruncationDdl\":false,\"DataTruncationErrorPolicy\":\"LOG_ERROR\",\"ApplyErrorInsertPolicy\":\"LOG_ERROR\",\"EventErrorPolicy\":\"IGNORE\",\"ApplyErrorEscalationPolicy\":\"LOG_ERROR\",\"RecoverableErrorCount\":-1,\"DataErrorEscalationCount\":0,\"TableErrorEscalationPolicy\":\"STOP_TASK\",\"RecoverableErrorInterval\":5,\"ApplyErrorDeletePolicy\":\"IGNORE_RECORD\",\"TableErrorEscalationCount\":0,\"FullLoadIgnoreConflicts\":true,\"DataErrorPolicy\":\"LOG_ERROR\",\"TableErrorPolicy\":\"SUSPEND_TABLE\"},\"ValidationSettings\":{\"ValidationPartialLobSize\":0,\"PartitionSize\":10000,\"RecordFailureDelayLimitInMinutes\":0,\"SkipLobColumns\":false,\"FailureMaxCount\":10000,\"HandleCollationDiff\":false,\"ValidationQueryCdcDelaySeconds\":0,\"ValidationMode\":\"ROW_LEVEL\",\"TableFailureMaxCount\":1000,\"RecordFailureDelayInMinutes\":5,\"MaxKeyColumnSize\":8096,\"EnableValidation\":true,\"ThreadCount\":5,\"RecordSuspendDelayInMinutes\":30,\"ValidationOnly\":false},\"TTSettings\":{\"TTS3Settings\":null,\"TTRecordSettings\":null,\"EnableTT\":false},\"FullLoadSettings\":{\"CommitRate\":10000,\"StopTaskCachedChangesApplied\":false,\"StopTaskCachedChangesNotApplied\":false,\"MaxFullLoadSubTasks\":8,\"TransactionConsistencyTimeout\":600,\"CreatePkAfterFullLoad\":false,\"TargetTablePrepMode\":\"DROP_AND_CREATE\"},\"TargetMetadata\":{\"ParallelApplyBufferSize\":0,\"ParallelApplyQueuesPerThread\":0,\"ParallelApplyThreads\":0,\"TargetSchema\":\"\",\"InlineLobMaxSize\":0,\"ParallelLoadQueuesPerThread\":0,\"SupportLobs\":true,\"LobChunkSize\":0,\"TaskRecoveryTableEnabled\":false,\"ParallelLoadThreads\":0,\"LobMaxSize\":32,\"BatchApplyEnabled\":false,\"FullLobMode\":false,\"LimitedSizeLobMode\":true,\"LoadMaxFileSize\":0,\"ParallelLoadBufferSize\":0},\"BeforeImageSettings\":null,\"ControlTablesSettings\":{\"historyTimeslotInMinutes\":5,\"HistoryTimeslotInMinutes\":5,\"StatusTableEnabled\":false,\"SuspendedTablesTableEnabled\":false,\"HistoryTableEnabled\":false,\"ControlSchema\":\"\",\"FullLoadExceptionTableEnabled\":false},\"LoopbackPreventionSettings\":null,\"CharacterSetSettings\":null,\"FailTaskWhenCleanTaskResourceFailed\":false,\"ChangeProcessingTuning\":{\"StatementCacheSize\":50,\"CommitTimeout\":1,\"BatchApplyPreserveTransaction\":true,\"BatchApplyTimeoutMin\":1,\"BatchSplitSize\":0,\"BatchApplyTimeoutMax\":30,\"MinTransactionSize\":1000,\"MemoryKeepTime\":60,\"BatchApplyMemoryLimit\":500,\"MemoryLimitTotal\":1024},\"ChangeProcessingDdlHandlingPolicy\":{\"HandleSourceTableDropped\":true,\"HandleSourceTableTruncated\":true,\"HandleSourceTableAltered\":true},\"PostProcessingRules\":null}",
  "CdcStartPosition": "checkpoint:V1#102#00000000/B803EBA0#0#0#*#0#277"
}

Um die JSON-Datei zu bearbeiten und wiederherzustellen, führe den Befehl create-replication-task aus.

Um beispielsweise die Datei task_backup.json zu verwenden, um eine AWS DMS-Replikationsaufgabe mit der Aufgaben-ID restored-dms-task zu erstellen, führe den folgenden Befehl aus:

aws dms create-replication-task --replication-task-identifier restored-dms-task --cli-input-json file://task_backup.json

Hinweis: Wenn du den replication-task-identifier in den Befehl aufnehmen, überschreibe den replication-task-identifier-Wert in der Datei task_backup.json.

Ähnliche Informationen

Angeben von Aufgabeneinstellungen für AWS DMS-Aufgaben

Erstellen von Aufgaben für die laufende Replikation mithilfe von AWS DMS

AWS OFFICIALAktualisiert vor einem Jahr