> For the complete documentation index, see [llms.txt](https://docs.editran.onesait.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.editran.onesait.com/documentacion-editran/connect-v3.1-en/administradores/backups.md).

# Backups

Performing regular backups is essential to ensure data recovery in the event of failures, configuration errors, loss of integrity, or planned maintenance.

Editran Connect is made up of multiple elements that must be backed up together to ensure a complete recovery of the environment.

***

## Components to back up

These are the different components recommended for backup; depending on the component and your system's needs, the strategy may differ.

| Component             | Description                                                                    |
| --------------------- | ------------------------------------------------------------------------------ |
| Database (PostgreSQL) | Contains all configuration, user, channel, and usage information.              |
| Configuration files   | The editran core modules have two configuration files that must be safeguarded |
| Temporary files       | Folder for ongoing or pending jobs.                                            |
| Logs                  | Log files useful for auditing and diagnostics.                                 |
| Binary repository     | Folder containing the system's own JAR/WAR files.                              |
| License file          | license file required for Editran to work                                      |

> ℹ️ *Note:* Paths may vary depending on the installation. Use the environment variables configured during installation or consult technical support.

***

## General recommendations

* Make **automated** backups outside business hours. Especially when you do not have exchanges with other Editran nodes.
* Use backup tools compatible with PostgreSQL (`pg_dump`, `pg_basebackup`).
* Verify the backups with periodic restore tests.
* Protect access to backup files with restrictive permissions.
* Store at least one off-site copy (for example, network/NAS/S3).

***

## Example of manual backup

### 2. Configuration files

The editran core modules have several configuration files that must be safeguarded, namely **ALL** the files in the directory `<core_installation_path>/cfg`. The backup of these files must be done when we perform the backup of the next item, otherwise we may find differences that compromise the backup.

### 1. PostgreSQL database

Editran has a PosgreSQL database engine that is configured and deployed during the installation process. For security reasons, the base configuration of this server only accepts requests from the database server itself; this means that if you want to perform backups from an external agent, you must take this into account.

The connection data to the DDBB is in the user variables created during the installation process:

| VARIABLE          | DESCRIPTION                         |
| ----------------- | ----------------------------------- |
| EDITRAN\_DB\_HOST | database server (default localhost) |
| EDITRAN\_DB\_PORT | database port (default 5432)        |
| EDITRAN\_DB\_PWD  | database connection password        |
| EDITRAN\_DB\_USER | database connection user            |

Together with the database engine, its administration tools are installed, and you can find them at `<installation_path_of_connect>/bin/pgsql/bin` (we recommend including it in the PATH environment variable of the OS users with which you run your backup routines).

At this point you can use different strategies with the installed tools; we are going to describe one method but there are more.

To back up the data we are going to use the PostgreSQL tools included in the Connect installation; to do this manually you would have to take the following steps:

1. The service of **DATA** of **Editran Connect** must be running
2. we open a Windows cmd on the server.
3. we go to the path \<connect\_installation\_directory>\bin\pgsql\bin
4. we run the command pg\_dumpall -U postgres > backup.sql
5. this will take a few seconds and we will have the file backup.sql inside the directory \<connect\_installation\_directory>\bin\pgsql\bin

**Here is an example of a .bat process to perform the backup**:

```cmd
@echo off
setlocal

:: Define date in YYYYMMDD format
for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMdd"') do set "DATESTR=%%i"

:: pg_dumpall path
set "PG_BIN=C:\EditranConnect\bin\pgsql\bin"
set "BACKUP_DIR=C:\backup"
set "FILENAME=backup_editran_%DATESTR%.sql"
set "FULLPATH=%BACKUP_DIR%\%FILENAME%"

:: Verify that the backup directory exists
if not exist "%BACKUP_DIR%" (
    echo The backup directory does not exist: %BACKUP_DIR%
    exit /b 1
)

:: Verify that the necessary environment variables are defined
if "%EDITRAN_DB_USER%"=="" (
    echo ERROR: The EDITRAN_DB_USER environment variable is not defined.
    exit /b 1
)

if "%EDITRAN_DB_PWD%"=="" (
    echo ERROR: The EDITRAN_DB_PWD environment variable is not defined.
    exit /b 1
)

:: Set the PGPASSWORD environment variable only in the script environment
set "PGPASSWORD=%EDITRAN_DB_PWD%"

:: Run the backup
"%PG_BIN%\pg_dumpall.exe" -U %EDITRAN_DB_USER% > "%FULLPATH%"
if errorlevel 1 (
    echo ERROR: The pg_dumpall command failed.
    exit /b 1
)

echo Backup completed successfully: %FULLPATH%

:: Clean sensitive variables
set "PGPASSWORD="
endlocal
```

## Example PostgreSQL backup restore

Here is an example of how to perform a restore. We strongly recommend that you perform restore tests before putting the server into production.

```cmd
@echo off
setlocal

:: Backup file to restore (you can change it to another name or pass it as a parameter)
set "BACKUP_FILE=C:\backup\backup_editran_YYYYMMDD.sql"

:: psql binary path
set "PG_BIN=C:\EditranConnect\bin\pgsql\bin"

:: Verify that the file exists
if not exist "%BACKUP_FILE%" (
    echo ERROR: The backup file was not found: %BACKUP_FILE%
    exit /b 1
)

:: Verify necessary environment variables
if "%EDITRAN_DB_USER%"=="" (
    echo ERROR: The EDITRAN_DB_USER environment variable is not defined.
    exit /b 1
)

if "%EDITRAN_DB_PWD%"=="" (
    echo ERROR: The EDITRAN_DB_PWD environment variable is not defined.
    exit /b 1
)

:: Set the password in the PGPASSWORD environment variable
set "PGPASSWORD=%EDITRAN_DB_PWD%"

:: Run the restore
type "%BACKUP_FILE%" | "%PG_BIN%\psql.exe" -U %EDITRAN_DB_USER% -h localhost -p 5432 -d postgres
if errorlevel 1 (
    echo ERROR: The restore failed.
    exit /b 1
)

echo Restore completed successfully from: %BACKUP_FILE%

:: Clean
set "PGPASSWORD="
endlocal
```

remember that you must also restore the .cfg files described above and they must be from the same point in time.

## Other files

### License file

The Editran license file (license.dat), which during installation was left in `<core_path>\bin\SL` is necessary for your Editran to operate, although the Editran team can provide you with a new one, we recommend that you make a backup.

### logs

Editran Connect generates two large collections of logs

* core logs, which are in the directory `<core_path>\log`
* connect logs, which are in the directory `<connect_path>\logs`

if, in the event of a disaster, you want to be able to perform a later analysis, we recommend saving the latest logs from both paths.

## Backup security

* Encrypt your backups
* Restrict read access to the administrators group.
* Perform backup rotation and secure deletion of old copies.
* Perform restore tests periodically

## Notice

> ⚠️ **Notice** The Editran development team provides this guide and the scripts detailed here as a guide and example so that system administrators know the necessary data to perform backups. It is the responsibility of the administrators of each installation to perform the relevant backups and restore tests in order to recover their system in the event of a disaster.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.editran.onesait.com/documentacion-editran/connect-v3.1-en/administradores/backups.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
