6a0b0de2659de200bccc3aebe9d4d0727c1ea5ff
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
-
Clone this repository
-
Install dependencies:
npm install -
Configure environment variables: Copy the
.env.examplefile to.envand fill in your credentials:cp .env.example .envThen edit the
.envfile 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
- The application connects to your MSSQL database using the provided credentials
- It executes a T-SQL backup command to create a backup file on the MSSQL server
- The backup file is downloaded from the SMB share to a local directory
- The local backup file is then uploaded to your specified S3 bucket
- 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.
Description
Languages
JavaScript
99.8%
Shell
0.2%