2018-07-26 07:37:30 +00:00
|
|
|
.. include:: /_includes/all.rst
|
2019-03-07 15:35:54 +00:00
|
|
|
.. include:: /_includes/snippets/__ANNOUNCEMENTS__.rst
|
2018-07-26 07:37:30 +00:00
|
|
|
|
2018-04-03 12:53:10 +00:00
|
|
|
.. _backup_and_restore_pgsql:
|
|
|
|
|
2018-04-03 12:59:06 +00:00
|
|
|
*****************************
|
|
|
|
Backup and restore PostgreSQL
|
|
|
|
*****************************
|
2018-04-03 12:53:10 +00:00
|
|
|
|
|
|
|
Backup and restore will be necessary when you are going to switch PostgreSQL versions.
|
|
|
|
Each version has its own data directory and is fully indepentend of other versions.
|
|
|
|
In case you want to switch to a different version, but still want to have your PostgreSQL databases
|
|
|
|
present, you must first backup the databases of your current version and import them into the
|
|
|
|
new version.
|
|
|
|
|
|
|
|
There are multiple ways to backup and restore. Chose the one which is most convenient for you.
|
|
|
|
|
|
|
|
|
|
|
|
**Table of Contents**
|
|
|
|
|
|
|
|
.. contents:: :local:
|
|
|
|
|
|
|
|
|
|
|
|
Backup
|
|
|
|
======
|
|
|
|
|
|
|
|
pg_dump
|
|
|
|
-------
|
|
|
|
|
2018-07-26 07:37:30 +00:00
|
|
|
|ext_lnk_tool_pg_dump| is bundled with each PHP container and reay to use.
|
|
|
|
To backup a database named ``my_db_name`` follow the below listed example:
|
2018-04-03 12:53:10 +00:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2018-06-03 18:45:01 +00:00
|
|
|
# Navigate to the Devilbox directory
|
|
|
|
host> cd path/to/devilbox
|
2018-04-03 12:53:10 +00:00
|
|
|
|
2018-06-03 18:45:01 +00:00
|
|
|
# Enter the PHP container
|
|
|
|
host> ./shell.sh
|
2018-04-03 12:53:10 +00:00
|
|
|
|
2018-06-03 18:45:01 +00:00
|
|
|
# Run pg_dump
|
|
|
|
devilbox@php-7.1.6 in /shared/httpd $ pg_dump -h pgsql -U postgres -W my_db_name > /shared/backups/pgsql/my_db_name.sql
|
2018-04-03 12:53:10 +00:00
|
|
|
|
2018-12-28 21:44:50 +00:00
|
|
|
|
|
|
|
phpPgAdmin
|
|
|
|
----------
|
|
|
|
|
|
|
|
If you do not like to use the command line for backups, you can use |ext_lnk_tool_phppgadmin|.
|
|
|
|
It comes bundled with the devilbox intranet.
|
|
|
|
|
|
|
|
|
2018-04-03 12:53:10 +00:00
|
|
|
Adminer
|
|
|
|
-------
|
|
|
|
|
2018-07-26 07:37:30 +00:00
|
|
|
If you do not like to use the command line for backups, you can use |ext_lnk_tool_adminer|.
|
|
|
|
It comes bundled with the devilbox intranet.
|
2018-04-03 12:53:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
Restore
|
|
|
|
=======
|
|
|
|
|
|
|
|
psql
|
|
|
|
----
|
|
|
|
|
|
|
|
In order to restore or import PostgreSQL databases on the command line, you need to use
|
2018-07-26 07:37:30 +00:00
|
|
|
|ext_lnk_tool_pgsql_restore|.
|
2018-04-03 12:53:10 +00:00
|
|
|
Here are a few examples for different file types:
|
|
|
|
|
|
|
|
``*.sql`` file
|
|
|
|
^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2018-06-03 18:45:01 +00:00
|
|
|
# Navigate to the Devilbox directory
|
|
|
|
host> cd path/to/devilbox
|
2018-04-03 12:53:10 +00:00
|
|
|
|
2018-06-03 18:45:01 +00:00
|
|
|
# Enter the PHP container
|
|
|
|
host> ./shell.sh
|
2018-04-03 12:53:10 +00:00
|
|
|
|
2018-06-03 18:45:01 +00:00
|
|
|
# Start the import
|
|
|
|
devilbox@php-7.1.6 in /shared/httpd $ psql -h pgsql -U postgres -W my_db_name < /shared/backups/pgsql/my_db_name.sql
|
2018-04-03 12:53:10 +00:00
|
|
|
|
|
|
|
``*.sql.gz`` file
|
|
|
|
^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2018-06-03 18:45:01 +00:00
|
|
|
# Navigate to the Devilbox directory
|
|
|
|
host> cd path/to/devilbox
|
2018-04-03 12:53:10 +00:00
|
|
|
|
2018-06-03 18:45:01 +00:00
|
|
|
# Enter the PHP container
|
|
|
|
host> ./shell.sh
|
2018-04-03 12:53:10 +00:00
|
|
|
|
2018-06-03 18:45:01 +00:00
|
|
|
# Start the import
|
|
|
|
devilbox@php-7.1.6 in /shared/httpd $ zcat /shared/backups/pgsql/my_db_name.sql.gz | psql -h pgsql -U postgres -W my_db_name
|
2018-04-03 12:53:10 +00:00
|
|
|
|
|
|
|
``*.sql.tar.gz`` file
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2018-06-03 18:45:01 +00:00
|
|
|
# Navigate to the Devilbox directory
|
|
|
|
host> cd path/to/devilbox
|
2018-04-03 12:53:10 +00:00
|
|
|
|
2018-06-03 18:45:01 +00:00
|
|
|
# Enter the PHP container
|
|
|
|
host> ./shell.sh
|
2018-04-03 12:53:10 +00:00
|
|
|
|
2018-06-03 18:45:01 +00:00
|
|
|
# Start the import
|
|
|
|
devilbox@php-7.1.6 in /shared/httpd $ tar xzOf /shared/backups/pgsql/my_db_name.sql.tar.gz | psql -h pgsql -U postgres -W my_db_name
|
2018-04-03 12:53:10 +00:00
|
|
|
|
|
|
|
|
2018-12-28 21:44:50 +00:00
|
|
|
phpPgAdmin
|
|
|
|
----------
|
|
|
|
|
|
|
|
|ext_lnk_tool_phppgadmin| supports importing many different formats out-of-the-box.
|
|
|
|
Simply select the compressed or uncompressed file and press ``Go`` in the import section of
|
|
|
|
the web interface.
|
|
|
|
|
|
|
|
|
2018-04-03 12:53:10 +00:00
|
|
|
Adminer
|
|
|
|
-------
|
|
|
|
|
2018-07-26 07:37:30 +00:00
|
|
|
|ext_lnk_tool_adminer| supports importing of plain (``*.sql``) or gzipped compressed
|
2018-04-03 12:53:10 +00:00
|
|
|
(``*.sql.gz``) files out-of-the-box. Simply select the compressed or uncompressed file and press
|
|
|
|
``Execute`` in the import section of the web interface.
|