Skip to content

Commit 2b600a1

Browse files
committed
Tweaks and fixes from testing.
1 parent 7ee8187 commit 2b600a1

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Changed
10+
- Database dump no includes the --no-tablespaces option to stop PROCESS provilege error. (Requires n98-magerun >4.3.0).
11+
- WordPress backup now runs search-replace on remote host export.
12+
- Magento database import now uses n98-magerun to import database.
13+
- WordPress import now uses wp-cli to import database.
14+
- Tidy up of unneeded variables.
15+
16+
917
## [1.7.0] - 2021-04-27
1018
### Added
1119
- New flag to add prefix to sales orders, invoices, credit memos and shipments.

utils/local_import.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ echo
55
echo -e "${txt_blue} Importing into local database(s).${txt_end}"
66
echo
77

8-
mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_DBASE<$local_backup_dir/latest-m2.sql
8+
n98-magerun db:import --drop-tables $local_backup_dir/latest-m2.sql
99

1010
if [ $_arg_wordpress == 'on' ]; then
11-
mysql -h$DB_WP_HOST -u$DB_WP_USER -p$DB_WP_PASS $DB_WP_DBASE<$local_backup_dir/latest-wp.sql
11+
cd wp
12+
sed -i '1s/^/SET SQL_MODE='\''ALLOW_INVALID_DATES'\'';\n\n/' $local_backup_dir/latest-wp.sql
13+
14+
wp db import $local_backup_dir/latest-wp.sql
1215
fi

utils/remote_backup.sh

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,53 @@ if [ $_arg_full == 'on' ]; then
99
fi
1010
printf "${bg_black}${txt_white}%-80s${txt_end}\n" " "
1111

12+
# Get the URL from n98, if the first option fails it'll try the next
13+
if ! CURRENT_URL=$(n98-magerun config:env:show system.default.web.secure.base_url); then
14+
CURRENT_URL=$(n98-magerun config:show web/secure/base_url)
15+
fi
16+
17+
new_domain=${CURRENT_URL,,}
18+
# remove http://
19+
new_domain=$(printf '%s' "${new_domain}" | sed 's/^http:\/\///g')
20+
# remove https://
21+
new_domain=$(printf '%s' "${new_domain}" | sed 's/^https:\/\///g')
22+
# remove ://
23+
new_domain=$(printf '%s' "${new_domain}" | sed 's/^:\/\///g')
24+
# remove //
25+
new_domain=$(printf '%s' "${new_domain}" | sed 's/^\/\///g')
26+
# remove www.
27+
new_domain=$(printf '%s' "${new_domain}" | sed 's/^www\.//g')
28+
# trim multiple and trailing slashes
29+
new_domain=$(echo ${new_domain} | sed 's:/*$::')
30+
31+
old_domain=${remote_domain,,}
32+
# remove http://
33+
old_domain=$(printf '%s' "${old_domain}" | sed 's/^http:\/\///g')
34+
# remove https://
35+
old_domain=$(printf '%s' "${old_domain}" | sed 's/^https:\/\///g')
36+
# remove ://
37+
old_domain=$(printf '%s' "${old_domain}" | sed 's/^:\/\///g')
38+
# remove //
39+
old_domain=$(printf '%s' "${old_domain}" | sed 's/^\/\///g')
40+
41+
# replace . with \.
42+
old_domain="${old_domain//./\.}"
43+
44+
# trim multiple and trailing slashes
45+
old_domain=$(echo ${old_domain} | sed 's:/*$::')
46+
1247
ssh -p "${remote_port}" "${remote_username}@${remote_host}" <<ENDSSH
1348
mkdir -p $remote_backup_dir
1449
cd $remote_magento_dir
1550
16-
REMOTE_DB_WP_HOST=$(n98-magerun config:env:show db.connection.wordpress.host)
17-
REMOTE_DB_WP_USER=$(n98-magerun config:env:show db.connection.wordpress.username)
18-
REMOTE_DB_WP_PASS=$(n98-magerun config:env:show db.connection.wordpress.password)
19-
REMOTE_DB_WP_DBASE=$(n98-magerun config:env:show db.connection.wordpress.dbname)
20-
2151
if [ $_arg_full == 'on' ]; then
22-
n98-magerun --quiet --no-interaction db:dump --compression="gzip" --strip="@log @sessions" --force $remote_backup_dir/latest-m2.sql.gz
52+
n98-magerun --quiet --no-interaction db:dump --no-tablespaces --compression="gzip" --strip="@log @sessions" --force $remote_backup_dir/latest-m2.sql.gz
2353
else
24-
n98-magerun --quiet --no-interaction db:dump --compression="gzip" --strip="@log @sessions @trade @sales $ignore_tables" --force $remote_backup_dir/latest-m2.sql.gz
54+
n98-magerun --quiet --no-interaction db:dump --no-tablespaces --compression="gzip" --strip="@log @sessions @trade @sales $ignore_tables" --force $remote_backup_dir/latest-m2.sql.gz
2555
fi
2656
2757
if [ $_arg_wordpress == 'on' ]; then
28-
n98-magerun --quiet --no-interaction db:dump --compression="gzip" --connection="wordpress" --force $remote_backup_dir/latest-wp.sql.gz
58+
cd wp
59+
wp search-replace 'http[s]?:\/\/(?:www\.)?$old_domain' 'https://$new_domain' --regex --export | gzip > $remote_backup_dir/latest-wp.sql.gz
2960
fi
3061
ENDSSH

utils/url_update.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,3 @@ echo -e ""
4141

4242
sed -i "s|www.$old_domain|$new_domain|g" "${local_backup_dir}/latest-m2.sql"
4343
sed -i "s|$old_domain|$new_domain|g" "${local_backup_dir}/latest-m2.sql"
44-
45-
if [ $_arg_wordpress == 'on' ]; then
46-
sed -i "s|www.$old_domain|$new_domain|g" "${local_backup_dir}/latest-wp.sql"
47-
sed -i "s|$old_domain|$new_domain|g" "${local_backup_dir}/latest-wp.sql"
48-
fi

0 commit comments

Comments
 (0)