Skip to content

Instantly share code, notes, and snippets.

@Ciantic
Last active March 16, 2016 10:34
Show Gist options
  • Select an option

  • Save Ciantic/b2ea3165bee8e24e2d89 to your computer and use it in GitHub Desktop.

Select an option

Save Ciantic/b2ea3165bee8e24e2d89 to your computer and use it in GitHub Desktop.
Export WordPress database to file, and then rsync to its destination
#!/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
#!/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
@Ciantic
Copy link
Author

Ciantic commented Mar 16, 2016

Parts of this is copy & pasted from: https://gist.github.com/cyberhobo/3853334

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment