Skip to content

skaiwlkr/db-transfer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📦 DB Transfer

DB Transfer is a simple Bash script to transfer PostgreSQL databases.
It allows you to:

  • Create dumps of a source or target database
  • Perform a full transfer (dump + restore) from one database to another

Ideal for development, testing, or backup purposes.

🚀 Features

  • Easy CLI usage via Bash
  • Uses standard PostgreSQL tools (pg_dump, psql)
  • Supports dump-only or full transfer modes
  • Automatically removes temporary dump files
  • Confirmation prompt before destructive operations

⚙️ Requirements

  • Bash
  • PostgreSQL CLI tools (pg_dump, psql)
  • Access to both databases via URI (e.g. postgresql://user:pass@host/dbname)

📦 Installing PostgreSQL Tools

macOS (with Homebrew):

brew install postgresql

Ubuntu/Debian:

sudo apt-get install postgresql-client

CentOS/RHEL:

sudo yum install postgresql

Windows: Download PostgreSQL from the official website or use Chocolatey:

choco install postgresql

📁 Project Structure

.
├── db-transfer.sh        # Main script
├── .env.transfer         # Example environment config (do not commit your own!)
└── README.md             # This file

🛠️ Setup

  1. Clone the repository
git clone https://github.com/your-username/db-transfer.git
cd db-transfer
  1. Create your own environment config
cp .env.transfer.example .env.transfer

Edit .env.transfer:

SOURCE_DB_URL="postgresql://USERNAME:PASSWORD@HOST/SOURCE_DB?sslmode=require"
TARGET_DB_URL="postgresql://USERNAME:PASSWORD@HOST/TARGET_DB"

⚠️ Do not commit .env.transfer to version control!

🧪 Usage

🔁 Full transfer (dump & restore)

./db-transfer.sh --restore

Steps:

  1. Creates a dump from SOURCE_DB_URL
  2. Prompts for confirmation before resetting the target schema
  3. Drops and recreates the public schema in TARGET_DB_URL
  4. Restores the dump to the target database
  5. Deletes the temporary dump file

💾 Dump only

Dump from source

./db-transfer.sh --dump SOURCE

Dump from target

./db-transfer.sh --dump TARGET

🔐 Security Tips

  • Use strong passwords and database access restrictions
  • Never commit sensitive .env files to a repository
  • The script includes safety prompts before destructive operations

🤝 Contributing

Pull requests and suggestions are welcome!
If you have ideas or questions, feel free to open an issue.

About

Simple transfer script, that creates dump and push's data to new database

Resources

Stars

Watchers

Forks

Languages