General information

Regularly creating database backups ensures the ability to quickly restore data in the event of complete data loss caused by administrator errors or malicious actions by third parties. Redundancy alone is not sufficient in this case, because if data in the PostgreSQL database cluster is accidentally or intentionally damaged or modified, those changes will be replicated across all cluster nodes. The NAICE installation package includes scripts that allow you to create or restore data.

Creating a data backup

Creating a database backup for a single-host PostgreSQL deployment in a container

The database backup is exported to the host machine in the <NAICE installation directory>/backups/ directory. By default, this is /etc/docker-naice/backups/.

To create a backup, run the following command on the NAICE server:

sudo docker exec -it naice-postgres /scripts/backup/backup.sh

Creating a database backup for a clustered PostgreSQL deployment in containers

The database backup is exported to the host machine in the <NAICE installation directory>/backups/ directory. By default, this is /etc/docker-naice/postgres/backups/.

Only users with sudo privileges can access the backups directory.

To create a backup, run the following command on the NAICE server:

On the first PostgreSQL cluster node:

sudo docker exec -it naice-postgres-1 /home/worker/scripts/backup/backup.sh

On the second PostgreSQL cluster node:

sudo docker exec -it naice-postgres-2 /home/worker/scripts/backup/backup.sh

A backup can be created on any cluster node regardless of whether it is in the Primary or Standby state.


Restoring data from a backup

Restoring data from a backup in a single-host PostgreSQL installation

To restore data, the database backup files must be located in the directory <NAICE installation directory>/backups/. By default, this is /etc/docker-naice/backups/.

To view the files in this directory sorted by modification time (newest first), use the ls -tlh <NAICE installation directory>/backups/ command:

$ ls -tlh /etc/docker-naice/backups/
total 72K
-rw-r--r-- 1 root root 22K Dec 12 15:07 naice_2024-12-12_22-07-23_279.tar.gz
-rw-r--r-- 1 root root 22K Dec 12 11:18 naice_2024-12-12_18-18-30_970.tar.gz

To restore data from the most recent backup, run the following command on the NAICE server:

sudo docker exec -it naice-postgres /scripts/backup/restore.sh

To restore data from a specific backup file, specify the file path using the -f parameter (inside the container all backup files are located in /var/backups/):

sudo docker exec -it naice-postgres /scripts/backup/restore.sh -f /var/backups/naice_2024-12-12_18-18-30_970.tar.gz

Restoring data from a backup in a PostgreSQL cluster deployment

To restore data, the database backup files must be located in the directory <NAICE installation directory>/postgres/backups/. By default, this is /etc/docker-naice/postgres/backups/.

Only users with sudo privileges can access the backups directory.

To view the files in this directory sorted by modification time (newest first), use the sudo ls -tlh <NAICE installation directory>/postgres/backups/ command:

$ sudo ls -tlh /etc/docker-naice/postgres/backups/
total 72K
-rw-r--r-- 1 worker root 22K Dec 12 15:17 naice_2024-12-12_22-17-26_667.tar.gz
-rw-r--r-- 1 root   root 22K Dec 12 11:54 naice_2024-12-12_18-18-30_970.tar.gz

Data restoration can be performed only on the node that is in the Primary state.

The procedure for determining the Primary node is described in v1.0_3.3 High-availability installation, section Checking the PostgreSQL cluster state.

After determining which node is in the Primary state, run the following command to restore data from the most recent backup:

If the Primary node is the first cluster node:

sudo docker exec -it naice-postgres-1 /home/worker/scripts/backup/restore.sh

If the Primary node is the second cluster node:

sudo docker exec -it naice-postgres-2 /home/worker/scripts/backup/restore.sh

To restore data from a specific backup file, specify the file path using the -f parameter (inside the container all backup files are located in /var/backups/):

If the Primary node is the first cluster node:

sudo docker exec -it naice-postgres-1 /home/worker/scripts/backup/restore.sh -f /var/backups/naice_2024-12-12_18-18-30_970.tar.gz

If the Primary node is the second cluster node:

sudo docker exec -it naice-postgres-2 /home/worker/scripts/backup/restore.sh -f /var/backups/naice_2024-12-12_18-18-30_970.tar.gz
  • Нет меток