### Example PostgreSQL Client Tool Usage - Windows Source: https://github.com/rostislavdugin/postgresus/blob/main/backend/tools/readme.md This command demonstrates how to access and verify the version of the pg_dump utility installed for PostgreSQL version 15 on a Windows system. It shows the typical path to the executable within the project's tooling directory. ```bash ./postgresql/postgresql-15/bin/pg_dump.exe --version ``` -------------------------------- ### Download PostgreSQL Client Tools - Windows Installation Script Source: https://github.com/rostislavdugin/postgresus/blob/main/backend/tools/readme.md This batch script is used on Windows to download and install PostgreSQL client tools. It typically fetches installers from EnterpriseDB and focuses on installing only the necessary client components without server installations. Administrator privileges may be required. ```cmd download_windows.bat ``` -------------------------------- ### Download PostgreSQL Client Tools - Linux Installation Script Source: https://github.com/rostislavdugin/postgresus/blob/main/backend/tools/readme.md This shell script is designed for Debian/Ubuntu Linux systems to download and install PostgreSQL client tools. It requires execute permissions to be set before running and utilizes the official PostgreSQL APT repository. Sudo privileges are necessary for package installation. ```bash chmod +x download_linux.sh ./download_linux.sh ``` -------------------------------- ### Download PostgreSQL Client Tools - macOS Installation Script Source: https://github.com/rostislavdugin/postgresus/blob/main/backend/tools/readme.md This shell script is for macOS to download and install PostgreSQL client tools. It relies on Homebrew being pre-installed and compiles PostgreSQL from source, which may result in a longer installation time compared to other platforms. This process focuses on client tools only. ```bash chmod +x download_macos.sh ./download_macos.sh ``` -------------------------------- ### Example PostgreSQL Client Tool Usage - Linux/macOS Source: https://github.com/rostislavdugin/postgresus/blob/main/backend/tools/readme.md This command illustrates how to access and check the version of the pg_dump utility for PostgreSQL version 15 on Linux or macOS. It reflects the standard file path structure expected after installation in the project's tooling directory. ```bash ./postgresql/postgresql-15/bin/pg_dump --version ``` -------------------------------- ### Add Docker Compose Example Source: https://github.com/rostislavdugin/postgresus/blob/main/contribute/how-to-add-notifier.md This example shows how to add a new Docker container to `backend/docker-compose.yml.example` for testing purposes. Sensitive data should be left blank. ```yaml version: '3.8' services: postgres: image: postgres:15 ports: ['5432:5432'] environment: POSTGRES_DB: postgres POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres volumes: - ./postgres-data:/var/lib/postgresql/data # Add a new service for your notifier's dependencies if needed # For example, a mock service or a database required by your notifier my_notifier_service: image: some-mock-image:latest ports: ['8080:8080'] environment: API_KEY: "" SENSITIVE_SECRET: "" ``` -------------------------------- ### Docker Commands for Postgresus Management Source: https://context7.com/rostislavdugin/postgresus/llms.txt Provides essential Docker Compose commands for managing the Postgresus application. These commands cover starting the service in detached mode, viewing real-time logs, and stopping the service. ```bash # Start the application docker compose up -d # View logs docker compose logs -f postgresus # Stop the application docker compose down # Access the web interface # Navigate to: http://localhost:4005 ``` -------------------------------- ### Install Postgresus with Bash Script (Linux) Source: https://github.com/rostislavdugin/postgresus/blob/main/README.md Automates the installation of Postgresus on Linux systems, including Docker and Docker Compose if not already present. It also configures Postgresus for automatic startup on system reboot. Ensure you have curl installed. ```bash sudo apt-get install -y curl && \ sudo curl -sSL https://raw.githubusercontent.com/RostislavDugin/postgresus/refs/heads/main/install-postgresus.sh \ | sudo bash ``` -------------------------------- ### Download Backup - REST API Source: https://context7.com/rostislavdugin/postgresus/llms.txt Allows direct download of a backup file from storage. A GET request to the specific backup's file endpoint (e.g., /api/v1/backups/{backupId}/file) initiates the download. The output is a binary file. ```bash curl -X GET http://localhost:4005/api/v1/backups/e5f6a7b8-c9d0-1234-ef01-234567890123/file \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \ --output backup_20251030.dump ``` -------------------------------- ### Docker Deployment - Docker Compose Source: https://context7.com/rostislavdugin/postgresus/llms.txt Provides a Docker Compose configuration for deploying Postgresus, suitable for production environments. This approach allows for more complex multi-container setups and easier management. ```yaml version: '3.8' services: postgresus: image: "rostislavdugin/postgresus:latest" container_name: postgresus ports: - "4005:4005" volumes: - "./postgresus-data:/postgresus-data" restart: unless-stopped environment: - POSTGRESUS_DB_HOST=postgres - POSTGRESUS_DB_PORT=5432 - POSTGRESUS_DB_USER=postgres - POSTGRESUS_DB_PASSWORD=postgres - POSTGRESUS_DB_NAME=postgres postgres: image: "postgres:15" container_name: postgres volumes: - "./postgres-data:/var/lib/postgresql/data" ports: - "5432:5432" restart: unless-stopped environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres - POSTGRES_DB=postgres ``` -------------------------------- ### Add .env Variables Example (Go) Source: https://github.com/rostislavdugin/postgresus/blob/main/contribute/how-to-add-notifier.md Demonstrates how to add new environment variables for testing purposes within `backend/internal/config/config.go`. These variables can be utilized in tests. ```go package config import ( "log" "os" "github.com/joho/godotenv" ) type Config struct { DatabaseURL string // Add other configurations MyNewNotifierAPIKey string } func LoadConfig() (*Config, error) { // Load .env file if it exists _ = godotenv.Load() config := &Config{ DatabaseURL: getEnv("DATABASE_URL", "postgres://user:password@host:port/dbname"), // Load other configurations MyNewNotifierAPIKey: getEnv("MY_NEW_NOTIFIER_API_KEY", ""), } return config, nil } func getEnv(key, fallback string) string { if value, ok := os.LookupEnv(key); ok { return value } return fallback } func main() { config, err := LoadConfig() if err != nil { log.Fatalf("Error loading config: %v", err) } println(config.MyNewNotifierAPIKey) } ``` -------------------------------- ### GET /api/v1/backups/{backupId}/file Source: https://context7.com/rostislavdugin/postgresus/llms.txt Download a backup file directly from storage. ```APIDOC ## GET /api/v1/backups/{backupId}/file ### Description Download a specific backup file directly from storage. ### Method GET ### Endpoint /api/v1/backups/{backupId}/file ### Parameters #### Path Parameters - **backupId** (string) - Required - The ID of the backup to download. ### Request Example ```bash curl -X GET http://localhost:4005/api/v1/backups/e5f6a7b8-c9d0-1234-ef01-234567890123/file \ -H "Authorization: Bearer " \ --output backup_file.dump ``` ### Response #### Success Response (200 OK) - Returns the binary backup file (application/octet-stream). #### Error Response (400 Bad Request) - **error** (string) - Indicates that the specified backup was not found. ```json { "error": "backup not found" } ``` ``` -------------------------------- ### List Backups - REST API Source: https://context7.com/rostislavdugin/postgresus/llms.txt Retrieves a list of all backups for a specific database. This is done via a GET request to the /api/v1/backups endpoint, with the database_id provided as a query parameter. Authentication is required. ```bash curl -X GET "http://localhost:4005/api/v1/backups?database_id=a1b2c3d4-e5f6-7890-abcd-ef1234567890" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." ``` -------------------------------- ### Health Check API Endpoints (Bash) Source: https://context7.com/rostislavdugin/postgresus/llms.txt Provides bash examples using curl to interact with the health check API. It demonstrates how to retrieve health check configuration for a database and fetch recent health check attempts, including sample JSON responses. ```bash # Get health check configuration for a database curl -X GET http://localhost:4005/api/v1/healthcheck-config/database/a1b2c3d4-e5f6-7890-abcd-ef1234567890 \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." # Response (200 OK): { "id": "h1i2j3k4-l5m6-7890-nopq-rst123456789", "databaseId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "enabled": true, "intervalSeconds": 300, "timeoutSeconds": 10 } # Get recent health check attempts curl -X GET http://localhost:4005/api/v1/healthcheck-attempts/database/a1b2c3d4-e5f6-7890-abcd-ef1234567890 \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." # Response (200 OK): [ { "id": "i2j3k4l5-m6n7-8901-opqr-stu234567890", "databaseId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "timestamp": "2025-10-30T15:00:00Z", "success": true, "responseTimeMs": 45, "errorMessage": null }, { "id": "j3k4l5m6-n7o8-9012-pqrs-tuv345678901", "databaseId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "timestamp": "2025-10-30T14:55:00Z", "success": true, "responseTimeMs": 42, "errorMessage": null } ] ``` -------------------------------- ### User Authentication - Sign Up Source: https://context7.com/rostislavdugin/postgresus/llms.txt Creates a new user account in the Postgresus system. Requires email and password in the request body. ```APIDOC ## POST /api/v1/users/signup ### Description Creates a new user account in the system. ### Method POST ### Endpoint /api/v1/users/signup ### Parameters #### Request Body - **email** (string) - Required - The email address for the new user. - **password** (string) - Required - The password for the new user. ### Request Example ```json { "email": "admin@example.com", "password": "SecurePass123!" } ``` ### Response #### Success Response (200 OK) - **message** (string) - Indicates successful user creation. #### Response Example ```json { "message": "User created successfully" } ``` #### Error Response (400 Bad Request) - **error** (string) - Describes the error, e.g., 'email already exists'. #### Error Response Example ```json { "error": "email already exists" } ``` ``` -------------------------------- ### User Authentication - Sign Up API (Bash) Source: https://context7.com/rostislavdugin/postgresus/llms.txt Creates a new user account in the Postgresus system. This API endpoint requires a JSON payload containing the user's email and password. It returns a success message upon creation or an error if the email already exists. ```bash curl -X POST http://localhost:4005/api/v1/users/signup \ -H "Content-Type: application/json" \ -d '{ "email": "admin@example.com", "password": "SecurePass123!" }' # Response (200 OK): { "message": "User created successfully" } # Error Response (400 Bad Request): { "error": "email already exists" } ``` -------------------------------- ### GET /api/v1/restores/{backupId} Source: https://context7.com/rostislavdugin/postgresus/llms.txt Get all restore attempts for a specific backup. ```APIDOC ## GET /api/v1/restores/{backupId} ### Description Retrieve a list of all restore attempts made for a particular backup. ### Method GET ### Endpoint /api/v1/restores/{backupId} ### Parameters #### Path Parameters - **backupId** (string) - Required - The ID of the backup to retrieve restore attempts for. ### Request Example ```bash curl -X GET http://localhost:4005/api/v1/restores/e5f6a7b8-c9d0-1234-ef01-234567890123 \ -H "Authorization: Bearer " ``` ### Response #### Success Response (200 OK) - An array of restore attempt objects, each containing details like id, backupId, status, startTime, endTime, and errorMessage. #### Response Example ```json [ { "id": "a7b8c9d0-e1f2-3456-0123-456789012345", "backupId": "e5f6a7b8-c9d0-1234-ef01-234567890123", "status": "completed", "startTime": "2025-10-30T10:15:00Z", "endTime": "2025-10-30T10:18:32Z", "errorMessage": null } ] ``` ``` -------------------------------- ### Database Configuration - Create Database Source: https://context7.com/rostislavdugin/postgresus/llms.txt Registers a new PostgreSQL database for backup management. Requires authentication and database configuration details. ```APIDOC ## POST /api/v1/databases/create ### Description Registers a new PostgreSQL database for backup management. ### Method POST ### Endpoint /api/v1/databases/create ### Parameters #### Request Headers - **Authorization** (string) - Required - Bearer token for authentication. #### Request Body - **name** (string) - Required - The name of the database configuration. - **type** (string) - Required - The type of database (e.g., 'postgresql'). - **postgresql** (object) - Required - PostgreSQL specific configuration. - **host** (string) - Required - The database host address. - **port** (integer) - Required - The database port. - **username** (string) - Required - The database username. - **password** (string) - Required - The database password. - **database** (string) - Required - The database name. - **version** (string) - Required - The PostgreSQL version. - **sslMode** (string) - Required - SSL mode (e.g., 'require'). - **period** (string) - Required - Backup period (e.g., 'daily'). - **timezoneLocation** (string) - Required - Timezone for backups. - **hour** (integer) - Required - Hour for scheduled backups. - **minute** (integer) - Required - Minute for scheduled backups. - **retention** (integer) - Required - Number of days to retain backups. - **notifiers** (array) - Optional - List of notification configurations. ### Request Example ```json { "name": "Production Database", "type": "postgresql", "postgresql": { "host": "db.example.com", "port": 5432, "username": "postgres", "password": "dbpassword", "database": "myapp_production", "version": "15", "sslMode": "require", "period": "daily", "timezoneLocation": "America/New_York", "hour": 4, "minute": 0, "retention": 30 }, "notifiers": [] } ``` ### Response #### Success Response (201 Created) - **id** (string) - The unique identifier of the created database configuration. - **userId** (string) - The ID of the user who created the configuration. - **name** (string) - The name of the database configuration. - **type** (string) - The type of database. - **postgresql** (object) - PostgreSQL configuration details. - **lastBackupTime** (string|null) - Timestamp of the last backup, or null if none. - **lastBackupErrorMessage** (string|null) - Error message from the last backup, or null. - **healthStatus** (string) - The health status of the database connection. #### Response Example ```json { "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "userId": "550e8400-e29b-41d4-a716-446655440000", "name": "Production Database", "type": "postgresql", "postgresql": { "host": "db.example.com", "port": 5432, "username": "postgres", "database": "myapp_production", "version": "15", "sslMode": "require", "period": "daily", "timezoneLocation": "America/New_York", "hour": 4, "minute": 0, "retention": 30 }, "lastBackupTime": null, "lastBackupErrorMessage": null, "healthStatus": "unknown" } ``` ``` -------------------------------- ### Docker Deployment - Simple Run Source: https://context7.com/rostislavdugin/postgresus/llms.txt Deploys Postgresus with an embedded PostgreSQL database using a single Docker run command. This command maps ports, mounts a volume for data persistence, and configures the container to restart automatically. It also includes commands to verify the container status and view logs. ```bash # Start Postgresus container docker run -d \ --name postgresus \ -p 4005:4005 \ -v ./postgresus-data:/postgresus-data \ --restart unless-stopped \ rostislavdugin/postgresus:latest # Verify container is running docker ps | grep postgresus # Check container logs docker logs -f postgresus ``` -------------------------------- ### Create Local Storage Configuration - Bash Source: https://context7.com/rostislavdugin/postgresus/llms.txt Configure a local storage destination for backup files by sending a POST request to the /api/v1/storages endpoint with local storage details. Requires Content-Type and Authorization headers. Includes local path for storage. ```bash curl -X POST http://localhost:4005/api/v1/storages \ -H "Content-Type: application/json" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \ -d '{ "name": "Local Storage", "type": "local", "localStorage": { "path": "/var/backups/postgresql" } }' ``` -------------------------------- ### GET /api/v1/backups Source: https://context7.com/rostislavdugin/postgresus/llms.txt Retrieve all backups for a specific database. ```APIDOC ## GET /api/v1/backups ### Description Retrieve a list of all backups associated with a specific database. ### Method GET ### Endpoint /api/v1/backups ### Parameters #### Query Parameters - **database_id** (string) - Required - The ID of the database to retrieve backups for. ### Request Example ```bash curl -X GET "http://localhost:4005/api/v1/backups?database_id=a1b2c3d4-e5f6-7890-abcd-ef1234567890" \ -H "Authorization: Bearer " ``` ### Response #### Success Response (200 OK) - An array of backup objects, each containing details like id, databaseId, status, startTime, endTime, size, compressedSize, errorMessage, and storageErrors. #### Response Example ```json [ { "id": "e5f6a7b8-c9d0-1234-ef01-234567890123", "databaseId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "status": "completed", "startTime": "2025-10-30T04:00:00Z", "endTime": "2025-10-30T04:05:23Z", "size": 157286400, "compressedSize": 39321600, "errorMessage": null, "storageErrors": null } ] ``` ``` -------------------------------- ### Database Management API Source: https://context7.com/rostislavdugin/postgresus/llms.txt Provides endpoints for creating, retrieving, and testing database configurations. ```APIDOC ## POST /api/v1/databases/create ### Description Creates a new database configuration. ### Method POST ### Endpoint /api/v1/databases/create ### Parameters #### Request Body - **database** (Database) - Required - The database configuration object. ### Request Example ```json { "name": "my_database", "host": "localhost", "port": 5432, "username": "user", "password": "password", "databaseName": "dbname" } ``` ### Response #### Success Response (200) - **Database** (Database) - The created database configuration object, including its ID. #### Response Example ```json { "id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "name": "my_database", "host": "localhost", "port": 5432, "username": "user", "password": "password", "databaseName": "dbname", "userId": "user-id-from-auth" } ``` ## GET /api/v1/databases ### Description Retrieves a list of all databases owned by the current user. ### Method GET ### Endpoint /api/v1/databases ### Parameters #### Query Parameters None ### Response #### Success Response (200) - **Database[]** (Database[]) - An array of database configuration objects. #### Response Example ```json [ { "id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "name": "my_database_1", "host": "localhost", "port": 5432, "username": "user", "password": "password", "databaseName": "dbname1", "userId": "user-id-from-auth" }, { "id": "b2c3d4e5-f6a7-8901-2345-67890abcdef0", "name": "my_database_2", "host": "remote.host.com", "port": 5432, "username": "remote_user", "password": "remote_password", "databaseName": "dbname2", "userId": "user-id-from-auth" } ] ``` ## POST /api/v1/databases/test-connection-direct ### Description Tests a database connection directly without saving the configuration. ### Method POST ### Endpoint /api/v1/databases/test-connection-direct ### Parameters #### Request Body - **database** (Database) - Required - The database configuration object to test. ### Request Example ```json { "host": "localhost", "port": 5432, "username": "test_user", "password": "test_password", "databaseName": "test_db" } ``` ### Response #### Success Response (200) Indicates that the database connection test was successful. #### Response Example ```json { "message": "Connection successful" } ``` ``` -------------------------------- ### List Restores - REST API Source: https://context7.com/rostislavdugin/postgresus/llms.txt Retrieves a list of all restore attempts associated with a particular backup. This is achieved through a GET request to the /api/v1/restores/{backupId} endpoint, requiring authentication. ```bash curl -X GET http://localhost:4005/api/v1/restores/e5f6a7b8-c9d0-1234-ef01-234567890123 \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." ``` -------------------------------- ### Database Configuration - List Databases Source: https://context7.com/rostislavdugin/postgresus/llms.txt Retrieves all configured databases for the authenticated user. ```APIDOC ## GET /api/v1/databases ### Description Retrieves all configured databases for the authenticated user. ### Method GET ### Endpoint /api/v1/databases ### Parameters #### Request Headers - **Authorization** (string) - Required - Bearer token for authentication. ### Response #### Success Response (200 OK) - Returns a list of database configuration objects. #### Response Example (Example response would be a JSON array of database objects, similar to the response of POST /api/v1/databases/create but potentially including more details or a list format.) ``` -------------------------------- ### Docker Deployment - Simple Run Source: https://context7.com/rostislavdugin/postgresus/llms.txt Deploy Postgresus with an embedded PostgreSQL database using a single Docker command. ```APIDOC ## Docker Deployment - Simple Run ### Description This section provides instructions for deploying Postgresus using a single `docker run` command, suitable for testing or simple setups. ### Command ```bash docker run -d \ --name postgresus \ -p 4005:4005 \ -v ./postgresus-data:/postgresus-data \ --restart unless-stopped \ rostislavdugin/postgresus:latest ``` ### Verification To verify the deployment, you can use the following Docker commands: - **Check if the container is running:** ```bash docker ps | grep postgresus ``` - **View container logs:** ```bash docker logs -f postgresus ``` ### Expected Log Output ``` Setting up data directory permissions... Initializing PostgreSQL database... Starting PostgreSQL... PostgreSQL is ready! Setting up database and user... Starting Postgresus application... Running database migrations... Server starting on :4005 ``` ``` -------------------------------- ### Create Migration Script Source: https://github.com/rostislavdugin/postgresus/blob/main/contribute/how-to-add-notifier.md An example migration script for creating a new table for a specific notifier. It uses UUID as the primary key and establishes a foreign key constraint with CASCADE DELETE. ```sql -- Create table for MyNewNotifier CREATE TABLE my_new_notifiers ( notifier_id UUID PRIMARY KEY, -- Add columns specific to MyNewNotifier api_key VARCHAR(255) NOT NULL, webhook_url VARCHAR(255) NOT NULL ); -- Add foreign key constraint to the notifiers table ALTER TABLE my_new_notifiers ADD CONSTRAINT fk_my_new_notifiers_notifier FOREIGN KEY (notifier_id) REFERENCES notifiers (id) ON DELETE CASCADE; ``` -------------------------------- ### POST /api/v1/storages/direct-test - Storage Configuration - Test Storage Connection Source: https://context7.com/rostislavdugin/postgresus/llms.txt Verifies the storage configuration by attempting to establish a connection before saving. ```APIDOC ## POST /api/v1/storages/direct-test ### Description Verifies the storage configuration by attempting to establish a connection before saving. ### Method POST ### Endpoint /api/v1/storages/direct-test ### Parameters #### Request Body - **name** (string) - Required - A name for the storage configuration. - **type** (string) - Required - The type of storage (e.g., "local", "s3"). - **localStorage** (object) - Optional - Configuration for local storage. - **path** (string) - Required - The file path for local storage. - **s3Storage** (object) - Optional - Configuration for S3 storage. - **endpoint** (string) - Required - The S3 endpoint URL. - **region** (string) - Required - The AWS region. - **bucket** (string) - Required - The S3 bucket name. - **accessKeyId** (string) - Required - The AWS access key ID. - **secretAccessKey** (string) - Required - The AWS secret access key. - **path** (string) - Optional - The path within the S3 bucket. ### Request Example ```json { "name": "Test S3 Storage", "type": "s3", "s3Storage": { "endpoint": "https://s3.amazonaws.com", "region": "us-east-1", "bucket": "my-postgres-backups", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "path": "production/backups" } } ``` ### Response #### Success Response (200) - **message** (string) - Indicates that the storage connection test was successful. #### Error Response (400) - **error** (string) - Describes the error encountered during the connection test. #### Response Example ```json { "message": "storage connection test successful" } ``` ```json { "error": "failed to connect to S3: AccessDenied: Access Denied" } ``` ``` -------------------------------- ### TypeScript Frontend Database API Client Source: https://context7.com/rostislavdugin/postgresus/llms.txt Provides a frontend API client for database operations using TypeScript. It includes functions to create database configurations, list databases for the current user, and directly test database connections. It relies on `apiHelper` for network requests and assumes the existence of `RequestOptions` and `getApplicationServer`. ```typescript import { apiHelper } from '../../../shared/api/apiHelper'; import type { Database } from '../model/Database'; export const databaseApi = { // Create a new database configuration async createDatabase(database: Database): Promise { const requestOptions = new RequestOptions(); requestOptions.setBody(JSON.stringify(database)); return apiHelper.fetchPostJson( `${getApplicationServer()}/api/v1/databases/create`, requestOptions, ); }, // List all databases for current user async getDatabases(): Promise { const requestOptions = new RequestOptions(); return apiHelper.fetchGetJson( `${getApplicationServer()}/api/v1/databases`, requestOptions, true, ); }, // Test database connection before saving async testDatabaseConnectionDirect(database: Database): Promise { const requestOptions = new RequestOptions(); requestOptions.setBody(JSON.stringify(database)); return apiHelper.fetchPostJson( `${getApplicationServer()}/api/v1/databases/test-connection-direct`, requestOptions, ); }, }; // Example usage in React component: // try { // await databaseApi.testDatabaseConnectionDirect(newDatabase); // const created = await databaseApi.createDatabase(newDatabase); // console.log('Database created:', created.id); // } catch (error) { // console.error('Failed to create database:', error); // } ``` -------------------------------- ### Deploy Postgresus with Docker Compose Source: https://github.com/rostislavdugin/postgresus/blob/main/README.md Defines a `docker-compose.yml` configuration for deploying Postgresus. This setup also uses an embedded PostgreSQL and persists data in `./postgresus-data`. The service is set to restart automatically unless explicitly stopped. ```yaml version: "3" services: postgresus: container_name: postgresus image: rostislavdugin/postgresus:latest ports: - "4005:4005" volumes: - ./postgresus-data:/postgresus-data restart: unless-stopped ``` -------------------------------- ### Reset Postgresus Admin Password using Docker Source: https://github.com/rostislavdugin/postgresus/blob/main/README.md This command allows you to reset the admin password for the Postgresus instance running in Docker. Ensure you have Docker installed and the postgresus container is running. Replace 'YourNewSecurePassword123' with your desired strong password. ```bash docker exec -it postgresus ./main --new-password="YourNewSecurePassword123" ``` -------------------------------- ### Create S3 Storage Configuration - Bash Source: https://context7.com/rostislavdugin/postgresus/llms.txt Configure an S3 storage destination for backup files by sending a POST request to the /api/v1/storages endpoint with S3 details. Requires Content-Type and Authorization headers. Includes S3 endpoint, region, bucket, credentials, and path. ```bash curl -X POST http://localhost:4005/api/v1/storages \ -H "Content-Type: application/json" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \ -d '{ "name": "AWS S3 Backups", "type": "s3", "s3Storage": { "endpoint": "https://s3.amazonaws.com", "region": "us-east-1", "bucket": "my-postgres-backups", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "path": "production/backups" } }' ``` -------------------------------- ### POST /api/v1/restores/{backupId}/restore Source: https://context7.com/rostislavdugin/postgresus/llms.txt Initiate a database restore from a specific backup. ```APIDOC ## POST /api/v1/restores/{backupId}/restore ### Description Initiate the process of restoring a database from a specified backup. ### Method POST ### Endpoint /api/v1/restores/{backupId}/restore ### Parameters #### Path Parameters - **backupId** (string) - Required - The ID of the backup to restore from. #### Request Body - **targetDatabaseId** (string) - Required - The ID of the database to restore the data into. ### Request Example ```json { "targetDatabaseId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" } ``` ### Response #### Success Response (200 OK) - **message** (string) - Indicates that the restore process has started successfully. #### Response Example ```json { "message": "restore started successfully" } ``` #### Error Response (400 Bad Request) - **error** (string) - Indicates that the target database was not found. ```json { "error": "target database not found" } ``` ``` -------------------------------- ### Storage Interface Implementation Source: https://context7.com/rostislavdugin/postgresus/llms.txt This section details the storage interface for various storage backends and the Storage struct. ```APIDOC ## Storage Interface ### Description Defines the `StorageFileSaver` interface for abstracting file saving operations across different storage backends and the `Storage` struct which holds configuration for various storage types. ### Methods #### `SaveFile(logger *slog.Logger, fileID uuid.UUID, file io.Reader) error` Saves a file to the configured storage backend. #### `GetFile(fileID uuid.UUID) (io.ReadCloser, error)` Retrieves a file from the configured storage backend. #### `DeleteFile(fileID uuid.UUID) error` Deletes a file from the configured storage backend. #### `Validate() error` Validates the storage configuration. #### `TestConnection() error` Tests the connection to the storage backend. ### Storage Struct Represents the configuration for a storage destination. - **ID** (uuid.UUID) - Unique identifier for the storage configuration. - **UserID** (uuid.UUID) - Identifier for the user who owns this storage configuration. - **Type** (StorageType) - The type of storage (e.g., Local, S3, Google Drive, NAS). - **Name** (string) - A user-defined name for the storage. - **LocalStorage** (*LocalStorage, optional) - Configuration for local file system storage. - **S3Storage** (*S3Storage, optional) - Configuration for S3-compatible storage. - **GoogleDriveStorage** (*GoogleDriveStorage, optional) - Configuration for Google Drive storage. - **NASStorage** (*NASStorage, optional) - Configuration for Network Attached Storage. ``` -------------------------------- ### Test Storage Connection - Bash Source: https://context7.com/rostislavdugin/postgresus/llms.txt Verify storage configuration by sending a POST request to the /api/v1/storages/direct-test endpoint with storage details. Requires Content-Type and Authorization headers. This endpoint tests the connection before saving the configuration. ```bash curl -X POST http://localhost:4005/api/v1/storages/direct-test \ -H "Content-Type: application/json" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \ -d '{ "name": "Test S3 Storage", "type": "s3", "s3Storage": { "endpoint": "https://s3.amazonaws.com", "region": "us-east-1", "bucket": "my-postgres-backups", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "path": "production/backups" } }' ``` -------------------------------- ### Docker Deployment - Docker Compose Source: https://context7.com/rostislavdugin/postgresus/llms.txt Deploy Postgresus using Docker Compose for a more robust and configurable production environment. ```APIDOC ## Docker Deployment - Docker Compose ### Description Deploy Postgresus in a production-ready environment using Docker Compose. This method allows for easier management of multiple services and configuration. ### docker-compose.yml (Example) ```yaml version: "3.8" services: postgresus: image: rostislavdugin/postgresus:latest container_name: postgresus ports: - "4005:4005" volumes: - ./postgresus-data:/postgresus-data restart: unless-stopped environment: # Example environment variables (adjust as needed for your setup) - POSTGRES_USER=admin - POSTGRES_PASSWORD=supersecretpassword - POSTGRES_DB=postgres - EXTERNAL_POSTGRES_HOST=localhost # If using an external PostgreSQL - EXTERNAL_POSTGRES_PORT=5432 - EXTERNAL_POSTGRES_USER=user - EXTERNAL_POSTGRES_PASSWORD=password - EXTERNAL_POSTGRES_DB=database # If you are using an external PostgreSQL database, you would define it here: # db: # image: postgres:14 # container_name: postgres_db # volumes: # - postgres_data:/var/lib/postgresql/data # environment: # POSTGRES_USER: user # POSTGRES_PASSWORD: password # POSTGRES_DB: database # ports: # - "5432:5432" # volumes: # postgres_data: # Define named volume for external DB data persistence ``` ### Usage 1. Save the content above as `docker-compose.yml` in your project directory. 2. Adjust the `environment` variables as necessary for your specific setup, especially if connecting to an external PostgreSQL instance. 3. Run the following command in the same directory as your `docker-compose.yml` file: ```bash docker-compose up -d ``` ### Management - To stop the services: `docker-compose down` - To view logs: `docker-compose logs -f postgresus` ``` -------------------------------- ### Database Configuration - List Databases API (Bash) Source: https://context7.com/rostislavdugin/postgresus/llms.txt Retrieves a list of all configured PostgreSQL databases associated with the authenticated user. This API endpoint requires a JWT token in the Authorization header for authentication. ```bash curl -X GET http://localhost:4005/api/v1/databases \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." ``` -------------------------------- ### Go Backend Database Service Implementation Source: https://context7.com/rostislavdugin/postgresus/llms.txt Implements the service layer for database management operations in Go. It includes methods for creating new database configurations, validating them, testing connections, and retrieving databases by user. Dependencies include `github.com/google/uuid` and internal user features. ```go package databases import ( "github.com/google/uuid" "postgresus-backend/internal/features/users" ) type DatabaseService struct { repository *DatabaseRepository } // CreateDatabase validates and stores a new database configuration func (s *DatabaseService) CreateDatabase(user *users.User, db *Database) (*Database, error) { db.UserID = user.ID if err := db.Validate(); err != nil { return nil, err } // Test connection before saving if err := db.TestConnection(logger.GetLogger()); err != nil { return nil, fmt.Errorf("connection test failed: %w", err) } if err := s.repository.Create(db); err != nil { return nil, err } return db, nil } // GetDatabasesByUser retrieves all databases owned by user func (s *DatabaseService) GetDatabasesByUser(user *users.User) ([]Database, error) { return s.repository.FindByUserID(user.ID) } // Example usage in controller: // database, err := databaseService.CreateDatabase(user, &request) // if err != nil { // return err // } ``` -------------------------------- ### Database Configuration - Create Database API (Bash) Source: https://context7.com/rostislavdugin/postgresus/llms.txt Registers a new PostgreSQL database for backup management within Postgresus. This endpoint requires an Authorization header with a JWT token and a JSON payload detailing the database's connection information, backup schedule, and retention policy. ```bash curl -X POST http://localhost:4005/api/v1/databases/create \ -H "Content-Type: application/json" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \ -d '{ "name": "Production Database", "type": "postgresql", "postgresql": { "host": "db.example.com", "port": 5432, "username": "postgres", "password": "dbpassword", "database": "myapp_production", "version": "15", "sslMode": "require", "period": "daily", "timezoneLocation": "America/New_York", "hour": 4, "minute": 0, "retention": 30 }, "notifiers": [] }' # Response (201 Created): { "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "userId": "550e8400-e29b-41d4-a716-446655440000", "name": "Production Database", "type": "postgresql", "postgresql": { "host": "db.example.com", "port": 5432, "username": "postgres", "database": "myapp_production", "version": "15", "sslMode": "require", "period": "daily", "timezoneLocation": "America/New_York", "hour": 4, "minute": 0, "retention": 30 }, "lastBackupTime": null, "lastBackupErrorMessage": null, "healthStatus": "unknown" } ``` -------------------------------- ### Create Email Notifier Configuration - Bash Source: https://context7.com/rostislavdugin/postgresus/llms.txt Set up an email notification channel by sending a POST request to the /api/v1/notifiers endpoint with email server details. Requires Content-Type and Authorization headers. Includes SMTP host, port, credentials, sender, recipient, and TLS usage. ```bash curl -X POST http://localhost:4005/api/v1/notifiers \ -H "Content-Type: application/json" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \ -d '{ "name": "Admin Email", "type": "email", "email": { "smtpHost": "smtp.gmail.com", "smtpPort": 587, "username": "noreply@example.com", "password": "app-specific-password", "from": "noreply@example.com", "to": "admin@example.com", "useTLS": true } }' ``` -------------------------------- ### User Authentication - Sign In Source: https://context7.com/rostislavdugin/postgresus/llms.txt Authenticates a user and returns a JWT token for subsequent API calls. Requires email and password. ```APIDOC ## POST /api/v1/users/signin ### Description Authenticates and receives a JWT token for subsequent API calls. ### Method POST ### Endpoint /api/v1/users/signin ### Parameters #### Request Body - **email** (string) - Required - The user's email address. - **password** (string) - Required - The user's password. ### Request Example ```json { "email": "admin@example.com", "password": "SecurePass123!" } ``` ### Response #### Success Response (200 OK) - **token** (string) - The JWT token for authentication. - **userId** (string) - The unique identifier of the user. #### Response Example ```json { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "userId": "550e8400-e29b-41d4-a716-446655440000" } ``` #### Error Response (400 Bad Request) - **error** (string) - Describes the error, e.g., 'invalid credentials'. #### Error Response Example ```json { "error": "invalid credentials" } ``` #### Error Response (429 Too Many Requests) - **error** (string) - Indicates that the rate limit has been exceeded. #### Error Response Example ```json { "error": "Rate limit exceeded. Please try again later." } ``` ```