Skip to content

    Restoring your first topic

    In this guide, you will restore a topic from a Backup to a Kafka cluster. This is a continuation from the Creating your first backup guide, where you created a backup of a Kafka topic.

    You will configure a Restore using:

    • The Storage where the topic data is backed up to.
    • The EventHub where the data will be restored to.
    • The Credentials to authenticate with the Kafka cluster.

    Pre-requisites

    To follow this guide, make sure you have the following tools available:

    Step 1: Draft a Restore

    First, you will start with defining a Draft Restore. A Draft Restore contains some basic information about the Restore, but does not contain any topics to restore yet. This allows you to use it as a working document and make changes before starting the Restore.

    Create the following Restore resource in Kubernetes:

    apiVersion: kannika.io/v1alpha
    kind: Restore
    metadata:
    name: "my-restore"
    spec:
    source: "my-volume-storage"
    sink: "my-kafka-cluster"
    sinkCredentialsFrom:
    credentialsRef:
    name: "sasl-creds"
    enabled: false # Optional, defaults to false
    config: {}

    In this example:

    Step 2: Configure the topics

    Next, you will configure the topics to restore.

    Let’s add the topic my-topic to the Restore:

    Add the following configuration to the Restore:

    apiVersion: kannika.io/v1alpha
    kind: Restore
    metadata:
    name: "my-restore"
    spec:
    9 collapsed lines
    sink: "my-volume-storage"
    source: "my-kafka-cluster"
    sourceCredentialsFrom:
    credentialsRef:
    name: "sasl-creds"
    enabled: false
    config:
    mapping:
    my-topic: # Topic in the Storage
    target: "my-topic" # Topic to restore to in the Kafka cluster

    In this example:

    • The Restore will read the data from my-topic, as defined by the key used in the mapping field. which was backed up in the previous guide, and stored in the Storage my-volume-storage.

    • The Restore will restore the data back to the topic my-topic in the EventHub my-kafka-cluster, defined by the target field.

    Step 3: Start the Restore

    Finally, now that all preparations are done, you are ready to start the restore!

    Start the Restore by setting the enabled field to true:

    apiVersion: kannika.io/v1alpha
    kind: Restore
    metadata:
    name: "my-restore"
    spec:
    sink: "my-volume-storage"
    source: "my-kafka-cluster"
    sourceCredentialsFrom:
    credentialsRef:
    name: "sasl-creds"
    enabled: false
    enabled: true
    config:
    mapping:
    my-topic:
    target: "my-topic"

    Step 4: Verify that the Restore is running

    To verify that the restore is running, run the following command:

    Terminal window
    $ kubectl get restores

    You should see output similar to the following:

    Terminal window
    NAME STATUS
    my-restore 🚀 Restoring

    You should also see the associated Job running:

    Terminal window
    $ kubectl get jobs

    You should see output similar to the following:

    Terminal window
    NAME COMPLETIONS DURATION AGE
    my-restore-a1b2c3 0/1 1s 1m

    Once the restore completes, all data has been restored to the my-topic topic in Kafka cluster.

    Step 5: Clean up the Restore (optional)

    To remove the Restore and its associated resources, simply delete it:

    Terminal window
    $ kubectl delete restore my-restore

    Conclusion

    You have successfully restored a Kafka topic from a Backup to a Kafka cluster!

    Have a look at the Restoring data from a Backup for a more thorough step-by-step guide on restoring data from a backup, or the Restore reference for more information on the available configuration options.

    If you require further assistance, don’t hesitate to reach out to us on Slack!