-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmigrateispconfig.sh
More file actions
224 lines (214 loc) · 10.4 KB
/
migrateispconfig.sh
File metadata and controls
224 lines (214 loc) · 10.4 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/bash
#
echo "############################################################"
echo "## Welcome ##"
echo "## Please take note of all instructions and ##"
echo "## recommendations ##"
echo "## ##"
echo "## If you have questions or problems you can always ##"
echo "## visit http://wiki.teris-cooper.de ##"
echo "## ##"
echo "## Alternatively you're welcome to send an email to ##"
echo "## admin [at] teris-cooper [dot] de ##"
echo "############################################################"
echo ""
echo "Please enter the IP address of your master (remote) server:"
read main_server
#common_args='-aPv --delete'
#common_args='-aPv --dry-run'
common_args='-aPv'
install_rsync="apt-get -y install rsync"
www_start="service apache2 start"
www_stop="service apache2 stop"
db_start="service mysql start"
db_stop="service mysql stop"
function menu {
clear
echo "############################################################"
echo "## Main menu ##"
echo "## ##"
echo "## Install RSync on the remote server (1)##"
echo "## Synchronize MySql (2)##"
echo "## Synchronize websites (3)##"
echo "## Synchronize email (4)##"
echo "## Synchronize passwords, users and other files (5)##"
echo "## Synchronize MailMan (6)##"
echo "## Synchronize LetsEncrypt (7)##"
echo "## Exit program (0)##"
echo "############################################################"
read -n 1 eingabe
}
function install {
clear
echo "Installing RSync on the remote server..."
ssh $main_server "$install_rsync"
echo "Installation complete"
menu
}
function db_migration {
clear
echo "###############################################################"
echo "###############################################################"
echo "############## Start MySql Migration #############"
echo "############## Step1: #############"
echo "############## Back up the remote databases #############"
echo "###############################################################"
echo "############## Step2: #############"
echo "############## Copy the backed-up databases #############"
echo "###############################################################"
echo "############## Step3: #############"
echo "############## Import the databases into MySql #############"
echo "###############################################################"
echo "###############################################################"
echo " "
echo "Back up the remote databases............................................................."
echo "Please enter the MySql password for the root user on the remote server $main_server:....."
read mysqlext
ssh $main_server "mkdir /root/mysql; mysqldump -u root -p$mysqlext --force --all-databases > /root/mysql/fulldump.sql"
clear
echo "Copy the backup.........................................................................."
rsync $common_args $main_server:/root/mysql/ /root/mysql
clear
echo "Import the backup........................................................................"
echo "Please enter the MySql password for the root user on this server:........................"
read mysql2
mysql -u root -p$mysql2 < /root/mysql/fulldump.sql
clear
echo "Upgrade mysql system tables if target server has newer mysql/mariadb versions..........................................................."
mysql_upgrade -uroot -p --force
#
# mysql_upgrade also does:
## mysqlcheck --all-databases --check-upgrade --auto-repair
## mysql < fix_priv_tables
#
# Therefore, no need to run again mysqlcheck with autorepair below
##echo "Check and repair the databases..........................................................."
##mysqlcheck -p -A --auto-repair
echo "###############################################################"
echo "###############################################################"
menu
}
function www_migration {
clear
echo "############################################################"
echo "############################################################"
echo "################## Web Migration ##################"
echo "################## Step1: ##################"
echo "################## Stop the webserver ##################"
echo "############################################################"
echo "################## Step2: ##################"
echo "################## Start the migration ##################"
echo "############################################################"
echo "################## Step3: ##################"
echo "################## Start the webserver ##################"
echo "############################################################"
$www_stop
rsync $common_args --compress --delete $main_server:/var/www/ /var/www
rsync $common_args --compress --delete $main_server:/var/log/ispconfig/httpd/ /var/log/ispconfig/httpd
$www_start
echo "############################################################"
echo "############################################################"
menu
}
function mail_migration {
clear
echo "############################################################"
echo "############################################################"
echo "################## Mail Migration ##################"
echo "################## Step1: ##################"
echo "################## Migrate vmail ##################"
echo "############################################################"
echo "################## Step2: ##################"
echo "################## Migrate vmail logs ##################"
echo "############################################################"
rsync $common_args --compress --delete $main_server:/var/vmail/ /var/vmail
rsync $common_args --compress --delete $main_server:/var/log/mail.* /var/log/
echo "############################################################"
echo "############################################################"
menu
}
function files_migration {
clear
echo "############################################################"
echo "############################################################"
echo "############# Files Migration #######"
echo "############# Step1: #######"
echo "############# Copy /var/backup #######"
echo "############################################################"
echo "############# Step2: #######"
echo "############# Copy /etc/passwd to /root/old-server #######"
echo "############################################################"
echo "############# Step3: #######"
echo "############# Copy /etc/group to /root/old-server #######"
echo "############################################################"
echo "############# Please manually install passwd+group #######"
echo "############# (see readme.md) #######"
echo "############################################################"
echo "############# Step4: #######"
echo "############# Copy /etc/apache2/sites-available #######"
echo "############################################################"
echo "############# Step5: #######"
echo "############# Copy /etc/apache2/sites-enabled #######"
echo "############################################################"
rsync $common_args $main_server:/var/backup/ /var/backup
rsync $common_args $main_server:/etc/passwd /root/old-server/
rsync $common_args $main_server:/etc/group /root/old-server/
rsync $common_args $main_server:/etc/shadow /root/old-server/
rsync $common_args $main_server:/etc/gshadow /root/old-server/
rsync $common_args $main_server:/etc/apache2/sites-available/ /etc/apache2/sites-available
rsync $common_args $main_server:/etc/apache2/sites-enabled/ /etc/apache2/sites-enabled
echo "############################################################"
echo "############################################################"
menu
}
function mailman_migration {
clear
echo "############################################################"
echo "############################################################"
echo "############ Mailman migration #############"
echo "############################################################"
rsync $common_args --compress --delete $main_server:/var/lib/mailman/lists /var/lib/mailman
rsync $common_args --compress --delete $main_server:/var/lib/mailman/data /var/lib/mailman
rsync $common_args --compress --delete $main_server:/var/lib/mailman/archives /var/lib/mailman
cd /var/lib/mailman/bin && ./genaliases
echo "############################################################"
echo "############################################################"
menu
}
function le_migration {
clear
echo "############################################################"
echo "############################################################"
echo "############ LetsEncrypt migration #############"
echo "############################################################"
rsync $common_args --compress $main_server:/etc/letsencrypt /etc
echo "############################################################"
echo "############################################################"
menu
}
function beenden {
clear
exit
}
menu
while [ "$eingabe" != "0" ]
do
case "$eingabe" in
0) beenden
;;
1) install
;;
2) db_migration
;;
3) www_migration
;;
4) mail_migration
;;
5) files_migration
;;
6) mailman_migration
;;
7) le_migration
;;
esac
done