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.
- 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
- Bash
- PostgreSQL CLI tools (
pg_dump,psql) - Access to both databases via URI (e.g.
postgresql://user:pass@host/dbname)
macOS (with Homebrew):
brew install postgresqlUbuntu/Debian:
sudo apt-get install postgresql-clientCentOS/RHEL:
sudo yum install postgresqlWindows: Download PostgreSQL from the official website or use Chocolatey:
choco install postgresql.
├── db-transfer.sh # Main script
├── .env.transfer # Example environment config (do not commit your own!)
└── README.md # This file
- Clone the repository
git clone https://github.com/your-username/db-transfer.git
cd db-transfer- Create your own environment config
cp .env.transfer.example .env.transferEdit .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.transferto version control!
./db-transfer.sh --restoreSteps:
- Creates a dump from
SOURCE_DB_URL - Prompts for confirmation before resetting the target schema
- Drops and recreates the
publicschema inTARGET_DB_URL - Restores the dump to the target database
- Deletes the temporary dump file
./db-transfer.sh --dump SOURCE./db-transfer.sh --dump TARGET- Use strong passwords and database access restrictions
- Never commit sensitive
.envfiles to a repository - The script includes safety prompts before destructive operations
Pull requests and suggestions are welcome!
If you have ideas or questions, feel free to open an issue.