wordpress-dev/dev/export-data.sh

23 lines
675 B
Bash
Executable File

#!/bin/sh
set -e
if [ -z "$1" ] ; then
_target_filename='.'
else
_target_filename="$1"
fi
_host="$_local_hostname.$_local_domain"
_cmd_wp_export="wp db export --dbuser=wordpress --dbpass=$_wp_db_passwd --add-drop-table data.sql"
_ssh_cmd="sshpass -p$_passwd_www ssh $_user_www@$_host"
_scp_cmd="sshpass -p$_passwd_www scp $_user_www@$_host:/tmp/wordpress.tar.gz"
echo "Exporting database ..."
$_ssh_cmd "cd /var/www/html/wordpress &&" $_cmd_wp_export
echo "Exporting files ..."
$_ssh_cmd 'cd /var/www/html/wordpress && tar czf /tmp/wordpress.tar.gz .'
$_ssh_cmd "rm /var/www/html/wordpress/data.sql"
$_scp_cmd "$_target_filename"
$_ssh_cmd 'rm /tmp/wordpress.tar.gz'