Skip to content

Commit fe6367e

Browse files
committed
Merge branch 'release/v1.5.0'
2 parents 4b2c26a + c2a5dc6 commit fe6367e

12 files changed

+130
-23
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88

9+
## [1.5.0] - 2020-10-14
10+
### Added
11+
- New fields for local file owner and group, and local shared directory
12+
- Chown is now run for all transferred files.
13+
- Theme files now regenerated.
14+
15+
### Changed
16+
- Added check for www in domains when replacing urls
17+
- Updated some of the messaging to be more uniform.
18+
19+
920
## [1.4.1] - 2020-09-08
1021
### Changed
1122
- Starting to unify messages.

MENU.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Use the below to generate the menu.sh file from the site [https://argbash.io/gen
44

55
```
66
#!/bin/bash
7-
# version="1.1.1"
7+
# version="1.5.0"
88
#
99
# This is an optional arguments-only example of Argbash potential
1010
#

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Magento 2 Production DB Sync v1.4.1
1+
# Magento 2 Production DB Sync v1.5.0
22

33
## About
44
A script to copy over a production database to another server, also has the ability to copy across imagery.
@@ -15,7 +15,7 @@ Currently the script is configured to attempt Magento 2 and WordPress database m
1515
## Installing and Updating
1616
To install or update the script run the following curl script
1717

18-
```curl -o- https://raw.githubusercontent.com/clivewalkden/bash-magento2-db-sync/v1.4.1/install.sh | bash```
18+
```curl -o- https://raw.githubusercontent.com/clivewalkden/bash-magento2-db-sync/master/install.sh | bash```
1919

2020
## Usage
2121
To copy over a production database first get a shell on the system you want to copy the data to.
@@ -30,12 +30,16 @@ $ db-sync.sh
3030
You can save a configuration file in the Magento directory to save answering some of the questions. An example is included in this repository [example.conf](./example.conf)
3131

3232
```bash
33-
remote_host=cotswoldcollections.com
34-
remote_domain=www.cotswoldcollections.com
33+
remote_host=domain.com
34+
remote_domain=www.domain.com
3535
remote_port=22
3636
remote_username=magento
3737
remote_magento_dir=/opt/magento/magento2
3838
remote_backup_dir=/opt/magento/backups
3939
remote_shared_deployment_dir=/opt/magento/deployment/shared/magento
40+
local_backup_dir=/opt/magento/backups
41+
local_shared_deployment_dir=/opt/magento/deployment/shared/magento
42+
local_file_user=magento
43+
local_file_group=magento
4044
```
4145

db-sync.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ source "${dbsyncutil}menu.sh"
1313

1414
# Make sure we are in a Magento directory
1515
if [ ! -f "bin/magento" ]; then
16-
echo -e "${bg_red}${txt_white} ${txt_end}"
16+
printf '%-1s %-80s %-1s' "${bg_red}${txt_white}" " " "${txt_end}"
1717
echo -e "${bg_red}${txt_white} You are not currently in a Magento directory ${txt_end}"
1818
echo -e "${bg_red}${txt_white} ${txt_end}"
1919
exit
@@ -32,12 +32,14 @@ echo -e "${txt_blue} Checking for local configuration file (${conf_file}). ${t
3232
echo -e ""
3333
if [[ -f "$conf_file" ]]; then
3434
. "$conf_file"
35+
echo -e "${txt_blue} Loaded from config. ${txt_end}"
3536
fi
3637

3738
set -e
3839

3940
# Set ${remote_host}
4041
source "${dbsyncutil}set_remote_host.sh"
42+
source "${dbsyncutil}set_local_vars.sh"
4143

4244
# Test Connection
4345
while true; do
@@ -88,11 +90,13 @@ echo -e ""
8890
n98-magerun setup:upgrade
8991
echo
9092
n98-magerun setup:di:compile
93+
echo
94+
n98-magerun setup:static-content:deploy -f -j8 en_GB en_US
9195
echo
9296
n98-magerun indexer:reindex
9397
echo
9498
n98-magerun cache:flush
9599

96100
echo -e "${bg_green}${txt_white}${txt_bold} ${txt_end}"
97-
echo -e "${bg_green}${txt_white}${txt_bold} Database migrated: ${txt_yellow}${domain} ${txt_end}"
101+
echo -e "${bg_green}${txt_white}${txt_bold} Database migrated: ${txt_yellow}${new_domain} ${txt_end}"
98102
echo -e "${bg_green}${txt_white}${txt_bold} ${txt_end}"

example.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ remote_username=magento
66
remote_magento_dir=/opt/magento/magento2
77
remote_backup_dir=/opt/magento/backups
88
remote_shared_deployment_dir=/opt/magento/deployment/shared/magento
9+
local_backup_dir=/opt/magento/backups
10+
local_shared_deployment_dir=/opt/magento/deployment/shared/magento
11+
local_file_user=magento
12+
local_file_group=magento

utils/local_backup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ if [ $_arg_local_backup == 'on' ]; then
66
echo -e "${txt_blue} Backing up local database(s).${txt_end}"
77
echo -e ""
88

9-
n98-magerun --ansi --root-dir="${PWD}" db:dump --compression="gzip" --force "../backups/$DATESTAMP-m2.sql.gz"
9+
n98-magerun --ansi --root-dir="${PWD}" db:dump --compression="gzip" --force "${local_backup_dir}/$DATESTAMP-m2.sql.gz"
1010

1111
if [ $_arg_wordpress == 'on' ]; then
12-
n98-magerun --ansi --root-dir="${PWD}" db:dump --compression="gzip" --connection="wordpress" --force "../backups/$DATESTAMP-wp.sql.gz"
12+
n98-magerun --ansi --root-dir="${PWD}" db:dump --compression="gzip" --connection="wordpress" --force "${local_backup_dir}/$DATESTAMP-wp.sql.gz"
1313
fi
1414
else
1515
# No local backup

utils/local_imagery_import.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ echo -e ""
77

88
# Set the default directories to transfer
99
source=("/pub/media/" "/wp/wp-content/uploads/")
10-
dest=("./pub/media/" "./wp/wp-content/uploads/")
10+
dest=("${local_shared_deployment_dir}/pub/media/" "${local_shared_deployment_dir}/wp/wp-content/uploads/")
1111

1212
for i in "${!source[@]}"; do
13-
rsync -rlDhP --exclude 'cache*' -e "ssh -p${remote_port}" "$remote_username@$remote_host:$remote_shared_deployment_dir${source[$i]}" "${dest[$i]}"
13+
rsync --recursive --links --human-readable --partial --progress --compress --perms --exclude 'cache*' -e "ssh -p${remote_port}" "$remote_username@$remote_host:$remote_shared_deployment_dir${source[$i]}" "${dest[$i]}"
14+
sudo chown -R $local_file_user:$local_file_group "${dest[$i]}"
1415
done

utils/local_import.sh

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

8-
mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_DBASE<../backups/latest-m2.sql
8+
mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_DBASE<$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<../backups/latest-wp.sql
11+
mysql -h$DB_WP_HOST -u$DB_WP_USER -p$DB_WP_PASS $DB_WP_DBASE<$local_backup_dir/latest-wp.sql
1212
fi

utils/menu.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
version="1.4.1"
2+
version="1.5.0"
33

44
die()
55
{
@@ -39,7 +39,7 @@ dbsync_print_help() {
3939
Options:
4040
-b, --local-backup: perform a backup before importing remote (off by default)
4141
-f, --full: full database dump (off by default)
42-
-w, --wordpress: include wordpress content (off by default)"
42+
-w, --wordpress: include wordpress content (off by default)"
4343
-v, --version: Prints version
4444
-h, --help: Prints help
4545

utils/remote_retrieve.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ echo -e ""
88
remote_m2_db_file="$remote_backup_dir/latest-m2.sql.gz"
99
remote_wp_db_file="$remote_backup_dir/latest-wp.sql.gz"
1010

11-
mkdir -p ../backups
11+
while [[ -z ${local_backup_dir} ]]; do
12+
# prompt and set ${local_backup_dir}
13+
read -p $'\e[1mLocal host backup directory\e[0m: ' -r -e local_backup_dir
1214

13-
scp -C -P "${remote_port}" "${remote_username}@${remote_host}:$remote_m2_db_file" ../backups/latest-m2.sql.gz
14-
gunzip -f ../backups/latest-m2.sql.gz
15+
if [[ -z ${local_backup_dir} ]]; then
16+
echo -e "${txt_red}Local host backup directory is required${txt_end}"
17+
fi
18+
done
19+
20+
mkdir -p "${local_backup_dir}"
21+
22+
scp -C -P "${remote_port}" "${remote_username}@${remote_host}:${remote_m2_db_file}" "${local_backup_dir}/latest-m2.sql.gz"
23+
gunzip -f "${local_backup_dir}/latest-m2.sql.gz"
1524

1625
if [ $_arg_wordpress == 'on' ]; then
17-
scp -C -P "${remote_port}" "${remote_username}@${remote_host}:$remote_backup_dir/latest-wp.sql.gz" ../backups/latest-wp.sql.gz
18-
gunzip -f ../backups/latest-wp.sql.gz
26+
scp -C -P "${remote_port}" "${remote_username}@${remote_host}:${remote_backup_dir}/latest-wp.sql.gz" "${local_backup_dir}/latest-wp.sql.gz"
27+
gunzip -f "${local_backup_dir}/latest-wp.sql.gz"
1928
fi

0 commit comments

Comments
 (0)