File tree Expand file tree Collapse file tree 12 files changed +130
-23
lines changed Expand file tree Collapse file tree 12 files changed +130
-23
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
7
7
## [ Unreleased]
8
8
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
+
9
20
## [ 1.4.1] - 2020-09-08
10
21
### Changed
11
22
- Starting to unify messages.
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Use the below to generate the menu.sh file from the site [https://argbash.io/gen
4
4
5
5
```
6
6
#!/bin/bash
7
- # version="1.1.1 "
7
+ # version="1.5.0 "
8
8
#
9
9
# This is an optional arguments-only example of Argbash potential
10
10
#
Original file line number Diff line number Diff line change 1
- # Magento 2 Production DB Sync v1.4.1
1
+ # Magento 2 Production DB Sync v1.5.0
2
2
3
3
## About
4
4
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
15
15
## Installing and Updating
16
16
To install or update the script run the following curl script
17
17
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 ```
19
19
20
20
## Usage
21
21
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
30
30
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 )
31
31
32
32
``` bash
33
- remote_host=cotswoldcollections .com
34
- remote_domain=www.cotswoldcollections .com
33
+ remote_host=domain .com
34
+ remote_domain=www.domain .com
35
35
remote_port=22
36
36
remote_username=magento
37
37
remote_magento_dir=/opt/magento/magento2
38
38
remote_backup_dir=/opt/magento/backups
39
39
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
40
44
```
41
45
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ source "${dbsyncutil}menu.sh"
13
13
14
14
# Make sure we are in a Magento directory
15
15
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} "
17
17
echo -e " ${bg_red}${txt_white} You are not currently in a Magento directory ${txt_end} "
18
18
echo -e " ${bg_red}${txt_white} ${txt_end} "
19
19
exit
@@ -32,12 +32,14 @@ echo -e "${txt_blue} Checking for local configuration file (${conf_file}). ${t
32
32
echo -e " "
33
33
if [[ -f " $conf_file " ]]; then
34
34
. " $conf_file "
35
+ echo -e " ${txt_blue} Loaded from config. ${txt_end} "
35
36
fi
36
37
37
38
set -e
38
39
39
40
# Set ${remote_host}
40
41
source " ${dbsyncutil} set_remote_host.sh"
42
+ source " ${dbsyncutil} set_local_vars.sh"
41
43
42
44
# Test Connection
43
45
while true ; do
@@ -88,11 +90,13 @@ echo -e ""
88
90
n98-magerun setup:upgrade
89
91
echo
90
92
n98-magerun setup:di:compile
93
+ echo
94
+ n98-magerun setup:static-content:deploy -f -j8 en_GB en_US
91
95
echo
92
96
n98-magerun indexer:reindex
93
97
echo
94
98
n98-magerun cache:flush
95
99
96
100
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} "
98
102
echo -e " ${bg_green}${txt_white}${txt_bold} ${txt_end} "
Original file line number Diff line number Diff line change @@ -6,3 +6,7 @@ remote_username=magento
6
6
remote_magento_dir=/opt/magento/magento2
7
7
remote_backup_dir=/opt/magento/backups
8
8
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
Original file line number Diff line number Diff line change @@ -6,10 +6,10 @@ if [ $_arg_local_backup == 'on' ]; then
6
6
echo -e " ${txt_blue} Backing up local database(s).${txt_end} "
7
7
echo -e " "
8
8
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"
10
10
11
11
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"
13
13
fi
14
14
else
15
15
# No local backup
Original file line number Diff line number Diff line change @@ -7,8 +7,9 @@ echo -e ""
7
7
8
8
# Set the default directories to transfer
9
9
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/" )
11
11
12
12
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]} "
14
15
done
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ echo -e ""
5
5
echo -e " ${txt_blue} Importing into local database(s).${txt_end} "
6
6
echo -e " "
7
7
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
9
9
10
10
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
12
12
fi
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
- version=" 1.4.1 "
2
+ version=" 1.5.0 "
3
3
4
4
die ()
5
5
{
@@ -39,7 +39,7 @@ dbsync_print_help() {
39
39
Options:
40
40
-b, --local-backup: perform a backup before importing remote (off by default)
41
41
-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)"
43
43
-v, --version: Prints version
44
44
-h, --help: Prints help
45
45
Original file line number Diff line number Diff line change @@ -8,12 +8,21 @@ echo -e ""
8
8
remote_m2_db_file=" $remote_backup_dir /latest-m2.sql.gz"
9
9
remote_wp_db_file=" $remote_backup_dir /latest-wp.sql.gz"
10
10
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
12
14
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"
15
24
16
25
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"
19
28
fi
You can’t perform that action at this time.
0 commit comments