Skip to content

Commit

Permalink
Merge pull request #2 from railwayapp-templates/rc/mysql-migrate-all-dbs
Browse files Browse the repository at this point in the history
Migrate all databases
  • Loading branch information
half0wl authored Feb 5, 2024
2 parents 38068cb + de3e3a0 commit 0530837
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ trap 'echo "An error occurred. Exiting..."; exit 1;' ERR
printf "${_BOLD}${_MAGENTA}"
echo "+-------------------------------------+"
echo "| |"
echo "| Railway Postgres Migration Script |"
echo "| Railway MySQL Migration Script |"
echo "| |"
echo "+-------------------------------------+"
printf "${_RESET}\n"
Expand Down Expand Up @@ -91,10 +91,28 @@ else
write_warn "The new database is not empty. Found OVERWRITE_DATABASE environment variable. Proceeding with restore."
fi

section "Dumping database from PLUGIN_URL"
section "Dumping database from PLUGIN_URL"

dump_file="plugin_dump.sql"
mysqldump -u $PLUGIN_USER -p$PLUGIN_PASSWORD -h $PLUGIN_HOST -P $PLUGIN_PORT --routines --triggers --events $PLUGIN_DB > $dump_file
# Dump all databases except sys databases
echo 'show databases;' \
| mysql \
-u $PLUGIN_USER \
-p$PLUGIN_PASSWORD \
-h $PLUGIN_HOST \
-P $PLUGIN_PORT \
| grep -Ev "Database|information_schema|mysql|performance_schema|sys" \
| xargs \
mysqldump \
-u $PLUGIN_USER \
-p$PLUGIN_PASSWORD \
-h $PLUGIN_HOST \
-P $PLUGIN_PORT \
--routines \
--triggers \
--events \
--databases \
$PLUGIN_DB > $dump_file

write_ok "Successfully saved dump to $dump_file"

Expand Down

0 comments on commit 0530837

Please sign in to comment.