#!/bin/bash : "${SOURCE:?Please provide a SOURCE which should be a database url}" : "${TARGET:?Please provide a TARGET which should be a database url}" dump_path=dump if [ -d "$dump_path" ]; then echo "/$dump_path already exists. Please remove ./$dump_path before running this script." exit 1 fi echo "Dumping database from $SOURCE to $TARGET via $dump_path" pg_dump \ --clean --if-exists \ --file ${dump_path} \ --format=directory \ --jobs 5 \ --no-acl \ --no-owner \ ${SOURCE} echo "Restoring database from $dump_path to $TARGET" pg_restore \ --clean --if-exists \ --dbname=${TARGET} \ --format=directory \ --jobs=5 \ --no-acl \ --no-owner \ $dump_path