#!/bin/bash
source $HOME/.gamerc

[ "$1" == "" ] && exec echo "Usage: $0 <DBName Postfix>"

POSTFIX=$1

DBNAME_LISTS=$(psql -U postgres -t -A -F',' -c "SELECT datname FROM pg_database WHERE datname LIKE 'N1%' AND strpos(datname, '_') = 0;")

for dbname in ${DBNAME_LISTS}; do
    backup_dbname="${dbname}${POSTFIX}"
    echo "${dbname} => ${backup_dbname}"
    #echo "psql -U postgres -c \"CREATE DATABASE \\\"${backup_dbname}\\\" TEMPLATE=\\\"${dbname}\\\";\""
    psql -U postgres -c "CREATE DATABASE \"${backup_dbname}\" TEMPLATE=\"${dbname}\";"
done
