Skip to content

Instantly share code, notes, and snippets.

@asaladino
Created February 3, 2019 13:22
Show Gist options
  • Select an option

  • Save asaladino/d372789118fdac73b5ffd7d8cb8fbf3e to your computer and use it in GitHub Desktop.

Select an option

Save asaladino/d372789118fdac73b5ffd7d8cb8fbf3e to your computer and use it in GitHub Desktop.
# Most of this script will work on bash/linux and powershell/windows.
## Dump SQL to remote location.
ssh user@server.com "mysqldump -P3306 -hmysql.server.com -u dbuser database > contents.sql"
## Get remote SQL dump file and transfer it locally.
scp -rp user@server.com:/remote/sql/dump/location/contents.sql C:\Temp\
## Remove the remote SQL Dump.
ssh user@server.com "rm contents.sql"
## Powershell only.
## Replace any strings in the sql dump.
(Get-Content C:\Temp\contents.sql).replace('server.com', 'server.lh') | Set-Content C:\Temp\contents.sql
(Get-Content C:\Temp\contents.sql).replace('https:', 'http:') | Set-Content C:\Temp\contents.sql
## Load the SQL dump locally.
mysql -u root -P3307 database -e "source C:\Temp\contents.sql"
## Remove the local SQL Dump.
rm C:\Temp\contents.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment