Skip to content

Commit 86ca6b6

Browse files
committed
Merge branch 'release/v1.3.0'
2 parents e04cf08 + 49f2ec3 commit 86ca6b6

File tree

9 files changed

+89
-39
lines changed

9 files changed

+89
-39
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+
## [1.3.0] - 2020-07-29
10+
### Added
11+
- local-backup option (enabled by default)
12+
13+
### Changed
14+
- Updated some variables to stop clashing with other scripts.
15+
16+
917
## [1.2.1] - 2020-07-10
1018
### Changed
1119
- Fixed message spacing issue.

MENU.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Menu Generation
2+
3+
Use the below to generate the menu.sh file from the site [https://argbash.io/generate](https://argbash.io/generate)
4+
5+
```
6+
#!/bin/bash
7+
# version="1.1.1"
8+
#
9+
# This is an optional arguments-only example of Argbash potential
10+
#
11+
# ARG_OPTIONAL_BOOLEAN([local-backup], [b], [perform a backup before importing remote], [off])
12+
# ARG_OPTIONAL_BOOLEAN([full], [f], [full database dump])
13+
# ARG_VERSION([echo test v$version])
14+
# ARG_HELP([The general script's help msg])
15+
# ARGBASH_GO
16+
17+
# [ <-- needed because of Argbash
18+
19+
# ] <-- needed because of Argbash
20+
```

README.md

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

33
## About
44
A script to copy over a production database to another server, also has the ability to copy across imagery.
@@ -14,7 +14,8 @@ Currently the script is configured to attempt Magento 2 and WordPress database m
1414

1515
## Installing and Updating
1616
To install or update the script run the following curl script
17-
```curl -o- https://raw.githubusercontent.com/clivewalkden/bash-magento2-db-sync/v1.2.1/install.sh | bash```
17+
18+
```curl -o- https://raw.githubusercontent.com/clivewalkden/bash-magento2-db-sync/v1.3.0/install.sh | bash```
1819

1920
## Usage
2021
To copy over a production database first get a shell on the system you want to copy the data to.

db-sync.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
#
66

77
# set path to allow calling util subdir files
8-
source "set_util"
8+
#source "set_util"
9+
dbsyncutil="$( dirname ${BASH_SOURCE[0]} )/utils/"
910

1011
# Load the menu and help
11-
source "${util}menu.sh"
12+
source "${dbsyncutil}menu.sh"
1213

1314
# Make sure we are in a Magento directory
1415
if [ ! -f "bin/magento" ]; then
@@ -19,7 +20,7 @@ if [ ! -f "bin/magento" ]; then
1920
fi
2021

2122
# Set global paths and functions
22-
source "${util}set_constants.sh"
23+
source "${dbsyncutil}set_constants.sh"
2324

2425
echo -e "${bg_black}${txt_white} ${txt_end}"
2526
echo -e "${bg_black}${txt_white} Copy over a production database to staging ${txt_end}"
@@ -34,33 +35,33 @@ fi
3435
set -e
3536

3637
# Set ${remote_host}
37-
source "${util}set_remote_host.sh"
38+
source "${dbsyncutil}set_remote_host.sh"
3839

3940
# Test Connection
4041
while true; do
4142
echo -e "\n"
4243
read -p "Would you like to test the connection? " yn
4344

4445
case $yn in
45-
[Yy]* ) source "${util}ssh_connection_test.sh"; break;;
46+
[Yy]* ) source "${dbsyncutil}ssh_connection_test.sh"; break;;
4647
[Nn]* ) break;;
4748
* ) echo "Please answer yes or no.";;
4849
esac
4950
done
5051

5152
# Run the remote backup
52-
source "${util}remote_backup.sh"
53-
source "${util}remote_retrieve.sh"
54-
source "${util}local_backup.sh"
55-
source "${util}url_update.sh"
53+
source "${dbsyncutil}remote_backup.sh"
54+
source "${dbsyncutil}remote_retrieve.sh"
55+
source "${dbsyncutil}local_backup.sh"
56+
source "${dbsyncutil}url_update.sh"
5657

5758
# Import the database(s)
5859
while true; do
5960
echo -e "\n"
6061
read -p "Are you ready to import databases to local system? " yn
6162

6263
case $yn in
63-
[Yy]* ) source "${util}local_import.sh"; break;;
64+
[Yy]* ) source "${dbsyncutil}local_import.sh"; break;;
6465
[Nn]* ) break;;
6566
* ) echo "Please answer yes or no.";;
6667
esac
@@ -72,7 +73,7 @@ while true; do
7273
read -p "Do you want to download the latest imagery? " yn
7374

7475
case $yn in
75-
[Yy]* ) source "${util}local_imagery_import.sh"; break;;
76+
[Yy]* ) source "${dbsyncutil}local_imagery_import.sh"; break;;
7677
[Nn]* ) break;;
7778
* ) echo "Please answer yes or no.";;
7879
esac

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dbsync_install_dir() {
77
}
88

99
dbsync_latest_version() {
10-
echo "v1.2.1"
10+
echo "v1.3.0"
1111
}
1212

1313
#

set_util

Lines changed: 0 additions & 3 deletions
This file was deleted.

utils/local_backup.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
#!/usr/bin/env bash
22

3-
# Backup the current local database
4-
echo -e "\n${txt_white}${bg_black}Backing up local database(s).${txt_end}\n"
3+
if [ $_arg_local_backup == 'on' ]; then
4+
# Backup the current local database
5+
echo -e "\n${txt_white}${bg_black}Backing up local database(s).${txt_end}\n"
56

6-
n98-magerun --root-dir="${PWD}" db:dump --compression="gzip" --force "../backups/$DATESTAMP-m2.sql.gz"
7+
n98-magerun --root-dir="${PWD}" db:dump --compression="gzip" --force "../backups/$DATESTAMP-m2.sql.gz"
78

8-
if [ ! -z $DB_WP_HOST ]; then
9-
mysqldump -u$DB_WP_USER -p$DB_WP_PASS $DB_WP_DBASE>"../backups/$DATESTAMP-wp.sql"
10-
gzip "../backups/$DATESTAMP-wp.sql"
9+
if [ ! -z $DB_WP_HOST ]; then
10+
mysqldump -u$DB_WP_USER -p$DB_WP_PASS $DB_WP_DBASE>"../backups/$DATESTAMP-wp.sql"
11+
gzip "../backups/$DATESTAMP-wp.sql"
12+
fi
13+
else
14+
# No local backup
15+
echo -e "\n${txt_white}${bg_black}Skipping local database(s) backup.${txt_end}\n"
1116
fi

utils/menu.sh

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

34
die()
45
{
56
local _ret=$2
67
test -n "$_ret" || _ret=1
7-
test "$_PRINT_HELP" = yes && dbsynchelp >&2
8+
test "$_PRINT_HELP" = yes && dbsync_print_help >&2
89
echo "$1" >&2
910
exit ${_ret}
1011
}
@@ -22,19 +23,24 @@ begins_with_short_option()
2223

2324
# THE DEFAULTS INITIALIZATION - OPTIONALS
2425
_arg_full="off"
26+
_arg_local_backup="off"
2527

26-
dbsynchelp() {
27-
cat <<-HEREDOC
28-
Magento 2 DB Sync v1.2.1
28+
dbsync_print_help() {
29+
cat <<HEREDOC
30+
31+
Magento 2 DB Sync v$version
2932
3033
Syncronize a database from production to staging, testing or development environments.
3134
3235
Make sure you are in a Magento 2 directory before trying to run any scripts.
3336
34-
Usage: db-sync.sh [-f|--(no-)full] [-h|--help]
37+
Usage: db-sync.sh [-b|--(no-)local-backup] [-f|--(no-)full] [-v|--version] [-h|--help]
3538
Options:
39+
-b, --local-backup, --no-local-backup: perform a backup before importing remote (off by default)
3640
-f, --full, --no-full: full database dump (off by default)
41+
-v, --version: Prints version
3742
-h, --help: Prints help
43+
3844
HEREDOC
3945
}
4046

@@ -45,16 +51,22 @@ parse_commandline()
4551
do
4652
_key="$1"
4753
case "$_key" in
48-
# The full argurment doesn't accept a value,
49-
# we expect the --full or -f, so we watch for them.
54+
-b|--no-local-backup|--local-backup)
55+
_arg_local_backup="on"
56+
test "${1:0:5}" = "--no-" && _arg_local_backup="off"
57+
;;
58+
-b*)
59+
_arg_local_backup="on"
60+
_next="${_key##-b}"
61+
if test -n "$_next" -a "$_next" != "$_key"
62+
then
63+
{ begins_with_short_option "$_next" && shift && set -- "-b" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
64+
fi
65+
;;
5066
-f|--no-full|--full)
5167
_arg_full="on"
5268
test "${1:0:5}" = "--no-" && _arg_full="off"
5369
;;
54-
# We support getopts-style short arguments clustering,
55-
# so as -f doesn't accept value, other short options may be appended to it, so we watch for -f*.
56-
# After stripping the leading -f from the argument, we have to make sure
57-
# that the first character that follows coresponds to a short option.
5870
-f*)
5971
_arg_full="on"
6072
_next="${_key##-f}"
@@ -63,14 +75,20 @@ parse_commandline()
6375
{ begins_with_short_option "$_next" && shift && set -- "-f" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
6476
fi
6577
;;
66-
# See the comment of option '--full' to see what's going on here - principle is the same.
78+
-v|--version)
79+
echo db-sync.sh - v$version
80+
exit 0
81+
;;
82+
-v*)
83+
echo db-sync.sh - v$version
84+
exit 0
85+
;;
6786
-h|--help)
68-
dbsynchelp
87+
dbsync_print_help
6988
exit 0
7089
;;
71-
# See the comment of option '-f' to see what's going on here - principle is the same.
7290
-h*)
73-
dbsynchelp
91+
dbsync_print_help
7492
exit 0
7593
;;
7694
*)

utils/remote_backup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Use the settings to check your connection
44
echo -e "\n${txt_white}${bg_black}Backing up remote database(s). ${txt_end}\n"
55
if [ $_arg_full == 'on' ]; then
6-
echo -e "${txt_white}${bg_black} Full customer and order backup.${txt_end}\n"
6+
echo -e "${txt_white}${bg_black} Full customer and order backup.${txt_end}\n"
77
fi
88

99
ssh -p "${remote_port}" "${remote_username}@${remote_host}" <<ENDSSH

0 commit comments

Comments
 (0)