Skip to content

Commit 43c9a6a

Browse files
committed
Merge branch 'release/v1.2.0'
2 parents ffeb3f6 + 0dc31df commit 43c9a6a

File tree

5 files changed

+100
-2
lines changed

5 files changed

+100
-2
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88

9+
## [1.2.0] - 2020-07-10
10+
### Added
11+
- Added menu option to allow full customer and order backups.
12+
13+
914
## [1.1.0] - 2020-07-10
1015
### Added
1116
- Installer

db-sync.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
# set path to allow calling util subdir files
88
source "set_util"
99

10+
# Load the menu and help
11+
source "${util}menu.sh"
12+
1013
# Make sure we are in a Magento directory
1114
if [ ! -f "bin/magento" ]; then
1215
echo -e "${bg_red} ${txt_end}"

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.1.0"
10+
echo "v1.2.0"
1111
}
1212

1313
#

utils/menu.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
3+
die()
4+
{
5+
local _ret=$2
6+
test -n "$_ret" || _ret=1
7+
test "$_PRINT_HELP" = yes && dbsynchelp >&2
8+
echo "$1" >&2
9+
exit ${_ret}
10+
}
11+
12+
13+
# Function that evaluates whether a value passed to it begins by a character
14+
# that is a short option of an argument the script knows about.
15+
# This is required in order to support getopts-like short options grouping.
16+
begins_with_short_option()
17+
{
18+
local first_option all_short_options='fh'
19+
first_option="${1:0:1}"
20+
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
21+
}
22+
23+
# THE DEFAULTS INITIALIZATION - OPTIONALS
24+
_arg_full="off"
25+
26+
dbsynchelp() {
27+
cat <<-HEREDOC
28+
Magento 2 DB Sync
29+
30+
Syncronize a database from production to staging, testing or development environments.
31+
32+
Usage: db-sync.sh [-f|--(no-)full] [-h|--help]
33+
Options:
34+
-f, --full, --no-full: full database dump (off by default)
35+
-h, --help: Prints help
36+
HEREDOC
37+
}
38+
39+
# The parsing of the command-line
40+
parse_commandline()
41+
{
42+
while test $# -gt 0
43+
do
44+
_key="$1"
45+
case "$_key" in
46+
# The full argurment doesn't accept a value,
47+
# we expect the --full or -f, so we watch for them.
48+
-f|--no-full|--full)
49+
_arg_full="on"
50+
test "${1:0:5}" = "--no-" && _arg_full="off"
51+
;;
52+
# We support getopts-style short arguments clustering,
53+
# so as -f doesn't accept value, other short options may be appended to it, so we watch for -f*.
54+
# After stripping the leading -f from the argument, we have to make sure
55+
# that the first character that follows coresponds to a short option.
56+
-f*)
57+
_arg_full="on"
58+
_next="${_key##-f}"
59+
if test -n "$_next" -a "$_next" != "$_key"
60+
then
61+
{ 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."
62+
fi
63+
;;
64+
# See the comment of option '--full' to see what's going on here - principle is the same.
65+
-h|--help)
66+
dbsynchelp
67+
exit 0
68+
;;
69+
# See the comment of option '-f' to see what's going on here - principle is the same.
70+
-h*)
71+
dbsynchelp
72+
exit 0
73+
;;
74+
*)
75+
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
76+
;;
77+
esac
78+
shift
79+
done
80+
}
81+
82+
parse_commandline "$@"

utils/remote_backup.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env bash
22

33
# Use the settings to check your connection
4-
echo -e "\n${txt_white}${bg_black}Backing up remote database(s).${txt_end}\n"
4+
echo -e "\n${txt_white}${bg_black}Backing up remote database(s). ${txt_end}\n"
5+
if [ $_arg_full == 'on' ]; then
6+
echo -e "\n${txt_white}${bg_black} Full customer and order backup.${txt_end}\n"
7+
fi
58

69
ssh -p "${remote_port}" "${remote_username}@${remote_host}" <<ENDSSH
710
mkdir -p $remote_backup_dir
@@ -17,7 +20,12 @@ REMOTE_DB_WP_USER=$(n98-magerun config:env:show db.connection.wordpress.username
1720
REMOTE_DB_WP_PASS=$(n98-magerun config:env:show db.connection.wordpress.password)
1821
REMOTE_DB_WP_DBASE=$(n98-magerun config:env:show db.connection.wordpress.dbname)
1922
23+
if [ $_arg_full == 'on' ]; then
24+
n98-magerun db:dump --compression="gzip" --strip="@log @sessions" --force $remote_backup_dir/latest-m2.sql.gz
25+
else
2026
n98-magerun db:dump --compression="gzip" --strip="@log @sessions @trade @sales" --force $remote_backup_dir/latest-m2.sql.gz
27+
fi
28+
2129
if [ ! -z $REMOTE_DB_WP_HOST ]; then
2230
mysqldump -h$REMOTE_DB_WP_HOST -u$REMOTE_DB_WP_USER -p$REMOTE_DB_WP_PASS $REMOTE_DB_WP_DBASE>$remote_backup_dir/latest-wp.sql
2331
gzip -f $remote_backup_dir/latest-wp.sql

0 commit comments

Comments
 (0)