2020-09-13 20:05:12 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
. ./config
|
|
|
|
|
|
|
|
[ -z "$1" ] && echo "Error - must supply backup directory" && exit 45
|
|
|
|
! [ -d "$1" ] && echo "Error - '$1' not a directory" && exit 65
|
2020-09-13 20:37:32 +00:00
|
|
|
|
2020-09-13 20:05:12 +00:00
|
|
|
backup_dir="$1"
|
2020-09-13 20:37:32 +00:00
|
|
|
timestamp="$(date +%s)"
|
|
|
|
backup_dir_dest="/tmp/wp-content-$timestamp"
|
|
|
|
backup_db_dest="/tmp/wp-db-$timestamp"
|
2020-09-13 20:05:12 +00:00
|
|
|
|
|
|
|
echo "restoring from $backup_dir"
|
|
|
|
|
2020-09-13 20:35:24 +00:00
|
|
|
ssh "$remote_ssh" "mv $remote_wp_path/wp-content $backup_dir_dest"
|
2020-09-13 20:40:21 +00:00
|
|
|
# TODO - only continue if backup succesful
|
2020-09-13 20:35:24 +00:00
|
|
|
echo "remote wp-content backed up as: $backup_dir_dest"
|
2020-09-13 20:23:17 +00:00
|
|
|
cat "$backup_dir/$backup_dir.tar" | ssh "$remote_ssh" "cd /; tar zxvf -"
|
2020-09-13 20:05:12 +00:00
|
|
|
|
2020-09-13 20:34:25 +00:00
|
|
|
# TODO - test database backup works
|
|
|
|
ssh "$remote_ssh" "wp db export $backup_db_dest --path=$remote_wp_path"
|
2020-09-13 20:40:21 +00:00
|
|
|
# TODO - only continue if backup succesful
|
2020-09-13 20:34:25 +00:00
|
|
|
echo "remote database backed up as: $backup_db_dest"
|
2020-09-13 20:05:12 +00:00
|
|
|
cat "./$backup_dir/$backup_dir.sql" | wp db import --ssh="$remote_ssh$remote_wp_path" -
|
|
|
|
|
|
|
|
wp search-replace "$local_protocol://$local_domain" "$remote_protocol://$remote_domain" \
|
|
|
|
--ssh="$remote_ssh$remote_wp_path" \
|
|
|
|
--skip-columns=guid \
|
|
|
|
--quiet
|
|
|
|
|
|
|
|
wp search-replace "$local_domain" "$remote_domain" \
|
|
|
|
--ssh="$remote_ssh$remote_wp_path" \
|
|
|
|
--skip-columns=guid \
|
|
|
|
--quiet
|