/
wpsql-cli.sh
executable file
·103 lines (100 loc) · 3.62 KB
/
wpsql-cli.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
source mysql-saudations/hello.sh
source mysql-commands/load-config.sh
OPERATION="loading..."
DATABASENAME=$DEFAULT_DATABASE
TABLE_PREFIX=$DEFAULT_TABLE_PREFIX
TABLES_SELECTED_ENTERED=""
TABLES_SELECTED_FOR_DUMP_LINE=""
SERVICENUMBER=""
case "$1" in
--all) echo "All tables: $DATABASENAME (all tables, ignoring table prefix previous entered)"
OPERATION="local-replace-remote"
SERVICENUMBER=1
;;
--prefixed) echo "Prefixed tables: only tables with prefix $TABLE_PREFIX inside database $DATABASENAME"
OPERATION="local-replace-remote"
SERVICENUMBER=2
;;
--posts-and-tax) echo "WordPress posts tables (${TABLE_PREFIX}posts, ${TABLE_PREFIX}postmeta, ${TABLE_PREFIX}termmeta, ${TABLE_PREFIX}terms, ${TABLE_PREFIX}term_relationships, ${TABLE_PREFIX}term_taxonomy) (Best choice for auto-sync)"
OPERATION="local-replace-remote"
SERVICENUMBER=3
;;
--posts) echo "Posts tables"
OPERATION="local-replace-remote"
SERVICENUMBER=4
;;
--post-type) echo "Posts type inside posts tables"
OPERATION="local-replace-remote"
SERVICENUMBER=6
;;
--options) echo "Options table - ${TABLE_PREFIX}options"
OPERATION="local-replace-remote"
SERVICENUMBER=5
;;
--name) echo "Custom tables"
OPERATION="local-replace-remote"
SERVICENUMBER=9
;;
-ia | --import-all )
OPERATION="remote-replace-local"
SERVICENUMBER=1
echo "not working... end"
exit
;;
-ip | --import-prefixed )
OPERATION="remote-replace-local"
SERVICENUMBER=2
;;
-a | --auto) echo "Selected 1 - Auto Sync"
OPERATION="auto-sync"
;;
-c | --compare) echo "Selected 1 - Auto Sync"
OPERATION="compare-content"
;;
-b | --backup) echo "Selected - Backup"
OPERATION="local-backup-all-dbs"
#source mysql-commands/local-backup-all-dbs.sh
;;
-db | --daily-backup) echo "Selected - Daily Backup"
OPERATION="daily-local-backup-all-dbs"
;;
-dr | --daily-replace) echo "Selected - Daily Replace"
OPERATION="daily-remote-replace-local"
;;
-w | --wizard) echo "Wizard"
source wizard.sh
;;
-h | --help) echo "HELP"
echo "Commands lists:"
echo "--all : all tables"
echo "--prefixed : prefixed tables: only tables with prefix $TABLE_PREFIX inside database $DATABASENAME"
echo "--posts-and-tax: wordPress posts tables (${TABLE_PREFIX}posts, ${TABLE_PREFIX}postmeta, ${TABLE_PREFIX}termmeta, ${TABLE_PREFIX}terms, ${TABLE_PREFIX}term_relationships, ${TABLE_PREFIX}term_taxonomy) (Best choice for auto-sync)"
echo "--posts : posts tables - ${TABLE_PREFIX}posts"
echo "--options : options table - ${TABLE_PREFIX}options"
echo "--name : prompt for user to enter custom tables separated by commas"
echo "--import-all : import from remote (probably production) to local (probably dev), all tables"
echo "--import-prefixed : prefixed tables: only tables with prefix $TABLE_PREFIX inside database $DATABASENAME"
echo "-a | --auto : auto sync between servers instances by highest wp post_id on selected table"
echo "-c | --compare : compare sql tables structure (diff) (ignores data)"
echo "-b | --backup : just perfom a backup"
echo "-w | --wizard : to run a step-by-step wizard"
echo "-h | --help : help text"
echo "Don't forget to config it, for detailed instructions see readme.MD"
source mysql-saudations/end.sh
;;
esac
if [ "$2" != "" ]; then
TABLE_PREFIX=$2
fi
if [ "$3" != "" ]; then
DATABASENAME=$3
fi
if [ "$1" == "" ] && [ "$2" == "" ] && [ "$3" == "" ];then
echo "Wizard started"
source wizard.sh
else
echo "Operation $OPERATION, prefix $TABLE_PREFIX, database $DATABASENAME, service $SERVICENUMBER, 1 $1, 2 $2, 3 $3"
source mysql-commands/table-generator.sh
source mysql-operations/$OPERATION.sh
fi