Skip to content

Instantly share code, notes, and snippets.

@wturrell
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wturrell/25f150396962d41da6aa to your computer and use it in GitHub Desktop.
Save wturrell/25f150396962d41da6aa to your computer and use it in GitHub Desktop.
Ampp3d Wordpress sync script - production to dev
#########################################################
# Remote MySQL Backup and Download
# Author: Brian Strickland
#
# 1) Log into a remote server
# 2) Run a MySQL dump on a database
# 3) Copies the dump to the local machine.
#
# You can use this for any database/server, just change
# the top parameters.
#########################################################
# Remote server info
remoteUser=william
remoteHost=servername
# DB Info
dbUser=ampp3d
dbPass=databasepassword
dbHost=thedatabase.server.com
dbName=ampp3d
# Backup options
backupName="$dbName"-$(date +"%Y%m%d-%H%M").sql
backupPath=/home/william/"$backupName"
downloadName=.
# Login to remote computer and run backup.
echo "Logging into $remoteHost…"
ssh -l "$remoteUser" "$remoteHost" "
# Run the mysql backup
echo "Running MySQL backup. This may take a while…"
mysqldump --opt "$dbName" > "$backupPath"
gzip "$backupPath"
echo "Backup complete."
# Close the session
exit;
"
# Copy the new database backup from remote host to current computer.
echo "Downloading $backupName.gz to $downloadName…"
scp "$remoteUser"@"$remoteHost":"$backupPath".gz "$downloadName"
echo "Download complete."
gzip -cd "$backupName".gz | mysql ampp3d
echo "Local DB overwritten."
mysql ampp3d < ampp3d-fetchdb-patch.sql
echo "Production to Dev SQL commands run"
echo "Finished ampped import - remember to turn off minify and varnish plugins"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment