.. Reminder for header structure:
  Parts (H1)          : #################### with overline
  Chapters (H2)       : ******************** with overline
  Sections (H3)       : ====================
  Subsections (H4)    : --------------------
  Subsubsections (H5) : ^^^^^^^^^^^^^^^^^^^^
  Paragraphs (H6)     : """"""""""""""""""""

.. meta::
  :description: Restoring the WAPT Server
  :keywords: restore, server, WAPT, PostgreSQL, pg_dumpall, FastCopy, WinSCP, documentation

.. _restore_server:

#########################
Restoring the WAPT Server
#########################

In case of a complete crash, restart a standard WAPT Server installation on your WAPT Server.
Then follow this procedure to restore your data.

By default, **we recommend retaining the same IP address and Fully Qualified Domain Name (FQDN) on the new WAPT server**.

To ensure that the new WAPT server has sufficient disk space for the repository, monitor the volume of your old WAPT server after performing the cleanup process. This will help you **determine the appropriate disk space requirements for the new server**.

.. tabs::

  .. tab:: Linux

    For Debian and derivatives:

    .. code-block:: shell

        du -sh /var/www/
        du -sh /opt/wapt/

    For Redhat and derivatives:

    .. code-block:: shell

      du -sh /opt/wapt/
      du -sh /var/www/html/

  .. tab:: Windows

    To display the size of the "C:\\wapt"
    repository, follow these steps:

    1- Open File Explorer and navigate to "This PC" or "My Computer."

    2- Locate and right-click on the "C:\\wapt" folder.
    
    3- From the context menu, select "Properties."
    
    4- In the Properties window, you will see various tabs. Ensure you are on the "General" tab.
    
    5- Look for the "Size" and "Size on disk" lines, which will display the total size of the folder and its contents.


.. _linux_restore_server:

*****
Linux
*****

* Stop WAPT related services on the WAPT Server.

.. code-block:: bash

  systemctl stop nginx
  systemctl stop waptserver
  systemctl stop waptserver-uwsgi
  systemctl stop wapttasks

* Restore the following directories.

.. tabs::

  .. code-tab:: bash Debian and derivatives

    /var/www/wapt/
    /var/www/wapt-host/
    /var/www/waptwua/
    /var/www/wads/
    /opt/wapt/conf/
    /opt/wapt/waptserver/ssl/
    /var/www/*.json

  .. code-tab:: bash RedHat and derivatives

    /var/www/html/wapt/
    /var/www/html/wapt-host/
    /var/www/html/waptwua/
    /var/www/html/wads/
    /opt/wapt/conf/
    /opt/wapt/waptserver/ssl/
    /var/www/html/*.json


* Restore the database (adapt the name of your file).
  The first command **deletes** the WAPT database (if it exists).
  Make sure that your dump file is correct before deleting!

.. warning::

  Check the encoding before creating the wapt database, if the dumped file is in en_US, your new base has to be en_US.

.. code-block:: bash

  cd /tmp
  sudo -u postgres psql -c "drop database wapt"
  sudo -u postgres psql -c "create database wapt with owner=wapt encoding='utf-8'"
  sudo -u postgres psql < /tmp/backup_wapt.sql

* Apply ownership rights to the restored folders.

.. tabs::

  .. code-tab:: bash Debian and derivatives

    chown -R wapt:www-data /var/www/wapt/
    chown -R wapt:www-data /var/www/wapt-host/
    chown -R wapt:www-data /var/www/waptwua/
    chown -R wapt:www-data /var/www/wads/
    chown -R wapt /opt/wapt/conf/
    chown -R wapt /opt/wapt/waptserver/ssl/

  .. code-tab:: bash RedHat and derivatives

    chown -R wapt:nginx /var/www/html/wapt/
    chown -R wapt:nginx /var/www/html/wapt-host/
    chown -R wapt:nginx /var/www/html/waptwua/
    chown -R wapt:nginx /var/www/html/wads/
    chown -R wapt /opt/wapt/conf/
    chown -R wapt /opt/wapt/waptserver/ssl/

.. important::

  **If you change waptserver Debian for Redhat or vice versa**. Don't forget to check somethings :

  Adapt news paths for parameter on your new server in the :file:`waptserver.ini`

  .. tabs::

    .. code-tab:: bash Debian and derivatives

      vi /opt/wapt/conf/waptserver.ini

      wapt_folder = /var/www/wapt
      waptwua_folder= /var/www/waptwua

    .. code-tab:: bash RedHat and derivatives

      vi /opt/wapt/conf/waptserver.ini

      wapt_folder = /var/www/html/wapt
      waptwua_folder= /var/www/html/waptwua
  
  Adapt path for the :file:`nginx` configuration.

  .. tabs::

    .. code-tab:: bash Debian and derivatives

      vi /etc/nginx/sites-available/wapt.conf

      Root paths must point to "/var/www/"
    
    .. code-tab:: bash RedHat and derivatives

      vi /etc/nginx/conf.d/wapt.conf

      Root paths must point to "/var/www/html/"


  Recreating symbolic links.

  .. tabs::

    .. code-tab:: bash Debian and derivatives

      ln -s /var/www/wapt/waptagent/waptsetup.exe waptsetup.exe
      ln -s /var/www/wapt/waptagent/waptsetup.exe waptsetup-tis.exe
      ln -s /var/www/wapt/waptagent/waptdeploy.exe waptdeploy.exe

    .. code-tab:: bash RedHat and derivatives

      ln -s /var/www/html/wapt/waptagent/waptsetup.exe waptsetup.exe
      ln -s /var/www/html/wapt/waptagent/waptsetup.exe waptsetup-tis.exe
      ln -s /var/www/html/wapt/waptagent/waptdeploy.exe waptdeploy.exe


* Run a Scanpackages on your repositories.


.. tabs::

  .. code-tab:: bash Debian and derivatives

    wapt-scanpackages /var/www/wapt/

  .. code-tab:: bash RedHat and derivatives

    wapt-scanpackages /var/www/html/wapt/

* Restart WAPT related services on the WAPT Server.

.. code-block:: bash

  systemctl start wapttasks
  systemctl start waptserver
  systemctl start nginx

* Launch the postconf.sh

.. code-block::

  /opt/wapt/waptserver/scripts/postconf.sh


.. _windows_restore_server:

*******
Windows
*******

* Stop WAPT related services on the WAPT Server.

.. code-block:: bash

  net stop WAPTServer
  net stop WAPTService
  net stop WAPTTftpServer

* Restore the following directories.

.. code-block:: bash

  C:\wapt\waptserver\repository\wapt
  C:\wapt\waptserver\repository\wapt-host
  C:\wapt\waptserver\repository\waptwua
  C:\wapt\waptserver\repository\wads
  C:\wapt\conf
  C:\wapt\waptserver\nginx\ssl

* Apply full rights to the folder :file:`C:\\wapt\\waptserver\\repository` for the "Network Service" group.

* Restore the database (adapt the name of your file).
  The first command **deletes** the WAPT database (if it exists).
  Make sure that your dump file is correct before deleting!

.. warning::

  Check the encoding before creating the wapt database, if the dumped file is in en_US, your new base has to be en_US.

.. code-block:: bash

  "C:\wapt\waptserver\pgsql-14\bin\psql.exe" -U postgres -c "drop database wapt;"
  "C:\wapt\waptserver\pgsql-14\bin\psql.exe" -U postgres -c "create database wapt with owner=wapt encoding='utf-8';"
  "C:\wapt\waptserver\pgsql-14\bin\psql.exe" -f c:\backup_wapt.sql -U postgres

* Scan package repositories.

.. code-block:: bash

  wapt-scanpackages "C:\wapt\waptserver\repository\wapt"

* Restart WAPT related services on the WAPT Server.

.. code-block:: bash

  net start WAPTServer
  net start WAPTService
  net start WAPTTftpServer
