Files
backupService/README.md
2025-08-02 11:27:35 +02:00

2.5 KiB

Database Backup Service

A Node.js application that continuously runs and creates backups of an MSSQL database, then uploads them to Amazon S3.

Features

  • Automatically backs up MSSQL database using T-SQL backup commands
  • Uploads backup files to Amazon S3
  • Runs continuously with scheduled backups
  • Configurable backup interval

Prerequisites

  • Node.js (v14 or higher recommended)
  • Access to an MSSQL database server
  • AWS S3 bucket and credentials

Setup

  1. Clone this repository

  2. Install dependencies:

    npm install
    
  3. Configure environment variables: Copy the .env.example file to .env and fill in your credentials:

    cp .env.example .env
    

    Then edit the .env file with your actual credentials:

    • AWS_ACCESS_KEY_ID: Your AWS access key ID
    • AWS_SECRET_ACCESS_KEY: Your AWS secret access key
    • AWS_REGION: Your AWS region (e.g., us-east-1)
    • S3_BUCKET_NAME: Your S3 bucket name
  • MSSQL_SERVER: Your MSSQL server address
  • MSSQL_PORT: Your MSSQL server port (default: 1433)
  • MSSQL_USER: Your MSSQL username
  • MSSQL_PASSWORD: Your MSSQL password
  • MSSQL_DATABASE: Your database name (default: eazybusiness)
  • BACKUP_FILE_PATH: Path where backup file is created on MSSQL server (default: F:\ez.bak)
  • SMB_ADDRESS: Your SMB share address (e.g., //server/share)
  • SMB_USERNAME: Your SMB username
  • SMB_PASSWORD: Your SMB password
  • SMB_DOMAIN: Your SMB domain (optional)
  • SMB_LOCAL_DOWNLOAD_PATH: Local path to download backup files (default: ./downloads)

Running the Application

Start the backup service:

npm start

For development with auto-restart:

npm run dev

How It Works

  1. The application connects to your MSSQL database using the provided credentials
  2. It executes a T-SQL backup command to create a backup file on the MSSQL server
  3. The backup file is downloaded from the SMB share to a local directory
  4. The local backup file is then uploaded to your specified S3 bucket
  5. This process repeats every 24 hours (configurable in the code)

Configuration

The backup interval can be adjusted in index.js by modifying the setInterval parameter:

// Currently set to 24 hours (86400000 milliseconds)
setInterval(runBackupProcess, 86400000);

File Path Note

The backup file is created on the MSSQL server at the path specified by BACKUP_FILE_PATH environment variable (default: F:\ez.bak). Make sure this path is accessible on your MSSQL server and has appropriate permissions.