add export wp script

This commit is contained in:
Ray Elliott 2020-09-05 14:04:21 +01:00
parent 81edc68811
commit 4c37540ab5
1 changed files with 15 additions and 61 deletions

View File

@ -1,75 +1,29 @@
#!/bin/sh #!/bin/sh
. ./config echo "Exporting from $url .."
if [ "$1" = 'local' ] ; then _timestamp="$(date +%s)"
src_url="$local_url"; _db_filename="wordpress-$_timestamp.db"
dest_url="$remote_url"; _archive_filename="wordpress-$_timestamp.tar.gz"
src_ssh="$local_ssh" _local_dest_dir="./data/$_target"
dest_ssh="$remote_ssh"
elif [ "$1" = 'remote' ] ; then
src_url="$remote_url";
dest_url="$local_url";
src_ssh="$remote_ssh"
dest_ssh="$local_ssh"
else
echo "error: must specify local or remote"
exit 5
fi
db_file="$wp_path/data.sql" ssh -T $ssh << EOSSH
tar_file="/tmp/wordpress.tar.gz" cd "$wp_path"
############## source
ssh -T $src_ssh << EOSSH
wp db export \ wp db export \
--path="$wp_path" \ --path="$wp_path" \
--dbuser="$wp_db_user" \ --dbuser="$wp_db_user" \
--dbpass="$wp_db_pass" \ --dbpass="$wp_db_pass" \
--add-drop-table \ --add-drop-table \
--allow-root \ --allow-root \
"$db_file" "/tmp/$_db_filename"
tar czf "$tar_file" "$wp_path" tar czf "/tmp/$_archive_filename" "$wp_path"
EOSSH EOSSH
scp "$src_ssh:$tar_file" "$tar_file" scp "$ssh:/tmp/$_archive_filename" "$_local_dest_dir/$_archive_filename"
scp "$ssh:/tmp/$_db_filename" "$_local_dest_dir/$_db_filename"
ssh -T $src_ssh << EOSSH exit
rm "$db_file" ssh -T $ssh << EOSSH
rm "$tar_file" rm "/tmp/$_db_filename"
rm "/tmp/$_archive_filename"
EOSSH EOSSH
############## destination
scp "$tar_file" "$dest_ssh:$tar_file"
ssh -T $dest_ssh << EOSSH
rm -Rf "$wp_path"
cd /
tar xzf "$tar_file"
wp db import \
--path="$wp_path" \
--dbuser="$wp_db_user" \
--dbpass="$wp_db_pass" \
--allow-root \
"$db_file"
rm "$db_file"
rm "$tar_file"
wp search-replace \
--path="$wp_path" \
--allow-root \
--skip-columns=guid \
"$src_url" \
"$dest_url"
wp option update home \
--path="$wp_path" \
--allow-root
wp option update home \
--path="$wp_path" \
--allow-root
EOSSH
mv "$tar_file" ./wordpress-"$(date +%s)".tar.gz