Last active
March 16, 2016 10:34
-
-
Save Ciantic/b2ea3165bee8e24e2d89 to your computer and use it in GitHub Desktop.
Export WordPress database to file, and then rsync to its destination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| wpdir=public_html | |
| dbfile=db-joawsefj3j14.sql | |
| wpconfig=$wpdir/wp-config.php | |
| if [ ! -f "$wpconfig" ]; then | |
| echo "$wpconfig not found." | |
| exit | |
| fi | |
| db=`sed -n -e "s/^define( *'DB_NAME', *'\([^']*\)'.*/\1/p" < $wpconfig` | |
| if [ -z $db ]; then | |
| echo "Database name not found in $wpconfig." | |
| exit | |
| fi | |
| user=`sed -n -e "s/^define( *'DB_USER', *'\([^']*\)'.*/\1/p" < $wpconfig` | |
| if [ -z $db ]; then | |
| echo "Database user not found in $wpconfig." | |
| exit | |
| fi | |
| pw=`sed -n -e "s/^define( *'DB_PASSWORD', *'\([^']*\)'.*/\1/p" < $wpconfig` | |
| if [ -z $db ]; then | |
| echo "Database credentials not found in $wpconfig." | |
| exit | |
| fi | |
| dbhost=`sed -n -e "s/^define( *'DB_HOST', *'\([^']*\)'.*/\1/p" < $wpconfig` | |
| if [ -z $dbhost ]; then | |
| echo "Database host not found in $wpconfig." | |
| exit | |
| fi | |
| mysql --user=$user --password=$pw --default-character-set=utf8 --host=$dbhost $db < $wpdir/$dbfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| wpdir=httpdocs | |
| dbfile=db-joawsefj3j14.sql | |
| wpconfig=$wpdir/wp-config.php | |
| [email protected]:public_html/ | |
| if [ ! -f "$wpconfig" ]; then | |
| echo "$wpconfig not found." | |
| exit | |
| fi | |
| db=`sed -n -e "s/^define( *'DB_NAME', *'\([^']*\)'.*/\1/p" < $wpconfig` | |
| if [ -z $db ]; then | |
| echo "Database name not found in $wpconfig." | |
| exit | |
| fi | |
| user=`sed -n -e "s/^define( *'DB_USER', *'\([^']*\)'.*/\1/p" < $wpconfig` | |
| if [ -z $db ]; then | |
| echo "Database user not found in $wpconfig." | |
| exit | |
| fi | |
| pw=`sed -n -e "s/^define( *'DB_PASSWORD', *'\([^']*\)'.*/\1/p" < $wpconfig` | |
| if [ -z $db ]; then | |
| echo "Database credentials not found in $wpconfig." | |
| exit | |
| fi | |
| dbhost=`sed -n -e "s/^define( *'DB_HOST', *'\([^']*\)'.*/\1/p" < $wpconfig` | |
| if [ -z $dbhost ]; then | |
| echo "Database host not found in $wpconfig." | |
| exit | |
| fi | |
| mysqldump --user=$user --password=$pw --host=$dbhost --default-character-set=utf8 $db > $wpdir/$dbfile | |
| rsync -az --delete --exclude 'wp-config.php' --exclude '.htaccess' --exclude 'wp-content/wp-cache-config.php' $wpdir/ $rsyncdest |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Parts of this is copy & pasted from: https://gist.github.com/cyberhobo/3853334