Skip to content

Instantly share code, notes, and snippets.

@matthewpoer
Created April 22, 2015 12:29
Show Gist options
  • Save matthewpoer/fa129978dd9de24142b3 to your computer and use it in GitHub Desktop.
Save matthewpoer/fa129978dd9de24142b3 to your computer and use it in GitHub Desktop.
Shell Script to dump and re-load a database as a background process so you don't have to sit and wait for it.
#/bin/sh
#
# NumberTwo.sh
# (because it's gonna take a dump)
#
# Dump and re-load some large database into a new sandbox. Helpful to have
# this in a script that we can run in the background when the database is
# large.
#
# Use it like this:
# `./NumberTwo.sh & exit`
#
# Will create a log file with timestamps as "NumberTwo.log"
#
echo "Begin" >> NumberTwo.log
date >> NumberTwo.log
mysqldump -h HOSTNAME -u USER -pPASSWORD database_one > database_one.sql
echo "Dump Complete" >> NumberTwo.log
date >> NumberTwo.log
mysqladmin -h HOSTNAME -u USER -pPASSWORD create database_two
echo "New DB Created" >> NumberTwo.log
date >> NumberTwo.log
mysql -h HOSTNAME -u USER -pPASSWORD database_two < database_one.sql
echo "New DB Loaded. Script Complete" >> NumberTwo.log
date >> NumberTwo.log
echo "Complete"
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment