Skip to content

Commit 8293099

Browse files
committed
Added shini for future ini configuration usage. Added localinstall for development testing. Added php and n98 remote path config options for servers with multi php available. Remote backups are now deleted after successful retrieval to help with error detection.
1 parent 0036edc commit 8293099

16 files changed

+414
-10
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88

9+
### Added
10+
- Support for multiple PHP bin version on remote host
11+
- Remote backup is deleted after retrieval to help detect any issues with the remote backup proceedure
12+
- Started work on ini configuration for better option support
13+
- Added sozo_imagify to the image directories ignored during image sync
14+
- shini for future ini config usage
15+
- Added localinstall for development testing
16+
17+
### Changed
18+
- Updated tables to drop when stripping content
19+
20+
921
## [1.7.3] - 2021-09-21
1022
### Changed
1123
- Added the `--all-tables` flag to the WordPress database backup as some tables were missed without it

MENU.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ Use the below to generate the menu.sh file from the site [https://argbash.io/gen
44

55
```
66
#!/bin/bash
7-
# version="1.7.3"
7+
# version="1.8.0"
88
#
99
# This is an optional arguments-only example of Argbash potential
1010
#
1111
# ARG_OPTIONAL_BOOLEAN([full], [f], [full database dump])
1212
# ARG_OPTIONAL_BOOLEAN([local-backup], [b], [perform a backup before importing remote], [off])
1313
# ARG_OPTIONAL_BOOLEAN([prefix], [p], [prefix invoices, orders, shipments etc], [off])
1414
# ARG_OPTIONAL_BOOLEAN([wordpress], [w], [include wordpress content], [off])
15+
# ARG_OPTIONAL_BOOLEAN([yes], [y], [answer yes to all options])
1516
# ARG_VERSION([echo test v$version])
1617
# ARG_HELP([The general script's help msg])
1718
# ARGBASH_GO
1819
19-
# [ <-- needed because of Argbash
20-
2120
# ] <-- needed because of Argbash
2221
```

README.md

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

33
## About
44
A script to copy over a production database to another server, also has the ability to copy across imagery.
@@ -39,6 +39,8 @@ remote_username=magento
3939
remote_magento_dir=/opt/magento/magento2
4040
remote_backup_dir=/opt/magento/backups
4141
remote_shared_deployment_dir=/opt/magento/deployment/shared/magento
42+
remote_php_path="/usr/bin/php"
43+
remote_n98_path="/usr/local/bin/n98-magerun"
4244
local_backup_dir=/opt/magento/backups
4345
local_shared_deployment_dir=/opt/magento/deployment/shared/magento
4446
local_file_user=magento

db-sync.ini

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Configuration ini file for db-sync (https://github.com/clivewalkden/bash-magento2-db-sync)
2+
[Global]
3+
remote_host="domain.com"
4+
remote_domain="www.domain.com"
5+
remote_port="22"
6+
remote_username="magento"
7+
remote_magento_dir="/opt/magento/magento2"
8+
remote_backup_dir="/opt/magento/backups"
9+
remote_shared_deployment_dir="/opt/magento/deployment/shared/magento"
10+
remote_php_path="/usr/bin/php"
11+
remote_n98_path="/usr/local/bin/n98-magerun"
12+
ignore_tables="mageplaza_smtp_log"
13+
14+
[Staging]
15+
local_backup_dir="/opt/magento/backups"
16+
local_shared_deployment_dir="/opt/magento/deployment/shared/magento"
17+
local_file_user="magento"
18+
local_file_group="magento"
19+
20+
[Development]
21+
local_backup_dir="/opt/magento/backups"
22+
local_shared_deployment_dir="/opt/magento/deployment/shared/magento"
23+
local_file_user="magento"
24+
local_file_group="magento"
25+
26+
[Local]
27+
local_backup_dir="/home/username/git/magento/backups"
28+
local_shared_deployment_dir="/home/username/git/magento/magento"
29+
local_file_user="username"
30+
local_file_group="username"

db-sync.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@ printf "${bg_black}${txt_white}%-80s${txt_end}\n" " "
3030
echo -e ""
3131
echo -e "${txt_blue} Checking for local configuration file (${conf_file}). ${txt_end}"
3232
echo -e ""
33-
if [[ -f "$conf_file" ]]; then
33+
# Load config from either .ini or .conf
34+
if [[ -f "$ini_file" ]]; then
35+
source "${dbsyncutil}shini.sh"
36+
source "${dbsyncutil}read_ini.sh"
37+
echo -e "${txt_blue} Loaded from ini. ${txt_end}"
38+
elif [[ -f "$conf_file" ]]; then
3439
. "$conf_file"
3540
echo -e "${txt_blue} Loaded from config. ${txt_end}"
41+
else
42+
echo -e "${txt_blue} No config to load. ${txt_end}"
3643
fi
3744

45+
3846
set -e
3947

4048
# Set ${remote_host}
@@ -56,6 +64,7 @@ done
5664
# Run the remote backup
5765
source "${dbsyncutil}remote_backup.sh"
5866
source "${dbsyncutil}remote_retrieve.sh"
67+
source "${dbsyncutil}cleanup.sh"
5968
source "${dbsyncutil}local_backup.sh"
6069
source "${dbsyncutil}url_update.sh"
6170

example.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ 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+
remote_php_path="/usr/bin/php"
10+
remote_n98_path="/usr/local/bin/n98-magerun"
911
local_backup_dir=/opt/magento/backups
1012
local_shared_deployment_dir=/opt/magento/deployment/shared/magento
1113
local_file_user=magento

install.sh

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

99
dbsync_latest_version() {
10-
echo "v1.7.3"
10+
echo "v1.8.0"
1111
}
1212

1313
#

localinstall.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
homedir=$( getent passwd "$USER" | cut -d: -f6 )
4+
dbsync=$homedir/.dbsync
5+
6+
echo -e " Installing locally"
7+
tar c ./ | pv | tar x -C $dbsync
8+
echo -e " Installation complete!"

utils/cleanup.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
echo
4+
printf "${bg_black}${txt_white}%-80s${txt_end}\n" " "
5+
printf "${bg_black}${txt_white}%-80s${txt_end}\n" " Deleting backups. "
6+
printf "${bg_black}${txt_white}%-80s${txt_end}\n" " "
7+
8+
# Delete remote db backups
9+
ssh -p "${remote_port}" "${remote_username}@${remote_host}" rm -f $remote_backup_dir/latest-m2.sql.gz
10+
ssh -p "${remote_port}" "${remote_username}@${remote_host}" rm -f $remote_backup_dir/latest-wp.sql.gz

utils/local_imagery_import.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ source=("/pub/media/" "/wp/wp-content/uploads/")
1010
dest=("${local_shared_deployment_dir}/pub/media/" "${local_shared_deployment_dir}/wp/wp-content/uploads/")
1111

1212
for i in "${!source[@]}"; do
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]}"
13+
rsync --recursive --links --human-readable --partial --progress --compress --perms --exclude={'cache*','sozo_imagify/*'} -e "ssh -p${remote_port}" "$remote_username@$remote_host:$remote_shared_deployment_dir${source[$i]}" "${dest[$i]}"
1414
sudo chown -R $local_file_user:$local_file_group "${dest[$i]}"
1515
done

0 commit comments

Comments
 (0)