.. SPDX-FileCopyrightText: 2024 Univention GmbH
..
.. SPDX-License-Identifier: AGPL-3.0-only

.. _backup-restore-restore:

Restore
=======

This section describes how to restore Nubus for Kubernetes from a backup
and how to get detailed information about it.

.. _backup-restore-create:

Restore a backup
----------------

This section describes how to restore Nubus to the same namespace
as the backup.
This type of restore requires a fresh, clean, and empty namespace.

.. important::

   :program:`Velero` supports restoring a backup to a different namespace.
   However, such a restore is only partially complete,
   because it doesn't overwrite Nubus's existing ``Order`` or ``ConfigMap`` Kubernetes objects,
   such as certificates.

   Describing a restore to a different namespace is beyond the scope of this document.

#. **Finding the backup for restore and the namespace**

   To find the backup to restore and the namespace to delete,
   follow the commands listed in :ref:`backup-restore-backup-describe`
   to list all backups and to view the details of a specific backup.
   You find the name of the namespace
   in the details in the ``Namespaces.included`` section
   of the output.

#. **Deleting the Kubernetes namespace used for the backup**

   To delete the namespace, use the commands in :numref:`backup-restore-create-restore-delete-namespace-listing`.

   .. code-block:: console
      :caption: Delete the Kubernetes namespace with your Nubus deployment
      :name: backup-restore-create-restore-delete-namespace-listing

      $ export NAMESPACE_FOR_NUBUS="your namespace including Nubus"
      $ kubectl delete namespace "$NAMESPACE_FOR_NUBUS"

   .. danger::

      Deleting the namespace terminates all pods running Nubus
      and your Nubus deployment ceases to exist.
      You can't stop or revert this action.

#. **Defining the settings for restore**

   To define the namespace where Velero runs and which backup to restore,
   initialize the environment variables in :numref:`backup-restore-create-restore-settings-listing`.

   .. code-block:: console
      :caption: Define settings for restore
      :name: backup-restore-create-restore-settings-listing

      $ export BACKUP_NAME="Name your backup to restore"
      $ export NAMESPACE_FOR_VELERO="your namespace for Velero"

#. **Restore a backup**

   To create a restore and tell Velero
   to restore your backup of Nubus to the same namespace as before,
   run the command in :numref:`backup-restore-create-restore-listing`.

   .. code-block:: console
      :caption: Create the restore
      :name: backup-restore-create-restore-listing

      $ velero restore create \
         --namespace "$NAMESPACE_FOR_VELERO" \
         --from-backup "$BACKUP_NAME"

   Velero begins the restore process.
   You can see activity in the logs of the Velero pod
   and appending data when you request :ref:`backup-restore-restore-describe`.

.. seealso::

   `Velero Docs - Restore Reference <https://velero.io/docs/latest/restore-reference/>`_
      for a reference of the restore command and information about the restore order.

.. _backup-restore-restore-describe:

Information about a restore
---------------------------

After you have created a restore,
you can retrieve various information about it, as shown in this section.
To set the environment variables used, see :numref:`backup-restore-create-restore-settings-listing`.

* To list all restores that Velero created so far, run the command in :numref:`backup-restore-describe-get-listing`.

  .. code-block:: console
     :caption: List all restores from a Velero configuration and its storage provider
     :name: backup-restore-describe-get-listing

     $ velero restore get --namespace "$NAMESPACE_FOR_VELERO"

* To view the details of a particular restore, run the command in :numref:`backup-restore-describe-listing`.

  For ``$RESTORE_NAME``, use the name from the listing of restores in :numref:`backup-restore-describe-get-listing`.

  .. code-block:: console
     :caption: Describe a restore
     :name: backup-restore-describe-listing

     $ velero restore describe "$RESTORE_NAME" --namespace "$NAMESPACE_FOR_VELERO"

* For a detailed listing with all restore item operations, and resources,
  use the command in :numref:`backup-restore-describe-details-listing`.

  For ``$RESTORE_NAME``, use the name from the listing of restores in :numref:`backup-restore-describe-get-listing`.

  .. code-block:: console
     :caption: Show details of a restore
     :name: backup-restore-describe-details-listing

     $ velero restore describe "$RESTORE_NAME" \
         --namespace "$NAMESPACE_FOR_VELERO" \
         --details
