Skip to content

yandearta/db2r2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DB to R2 Backup

This script automates the process of backing up all user databases from a MySQL server and uploading the backups to a Cloudflare R2 bucket.

Features

  • Connects to a MySQL server using provided credentials.
  • Fetches a list of all databases and filters out system databases.
  • Creates a compressed backup for each user database.
  • Uploads each backup file to a specified Cloudflare R2 bucket.
  • Uses environment variables for configuration, ensuring security and flexibility.

Prerequisites

  • Bun installed on your system.
  • mysqldump command-line utility available in your system's PATH.
  • Access to a MySQL server.
  • A Cloudflare R2 bucket and API credentials.

Installation

  1. Clone the repository:

    git clone https://github.com/yandearta/db2r2.git
    cd db2r2
  2. Install dependencies:

    bun install
  3. Configure environment variables:

    Create a .env file in the root of the project by copying the example file:

    cp .env.example .env

    Then, edit the .env file with your database and R2 credentials:

    DB_HOST=your_database_host
    DB_PORT=your_database_port
    DB_USER=your_database_user
    DB_PASSWORD=your_database_password
    
    R2_ACCESS_KEY=your_r2_access_key
    R2_SECRET_KEY=your_r2_secret_key
    R2_ENDPOINT=your_r2_endpoint
    R2_BUCKET=your_r2_bucket
    

Usage

To run the backup script, use the following command:

bun start

This will execute the src/backup.ts script, which performs the database backups and uploads them to your R2 bucket.

Linting

This project uses ESLint for code quality. To run the linter, use:

bun lint

To automatically fix linting issues, run:

bun lint:fix

About

Automated MySQL database backups to Cloudflare R2.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published