-
Notifications
You must be signed in to change notification settings - Fork 1
/
Envoy.blade.php
188 lines (163 loc) · 5.69 KB
/
Envoy.blade.php
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
@servers(['sfo2' => '[email protected]', 'qq3' => '[email protected]'])
#step1 CN备份用户相关表后,导出到sfo2,
#step2 从sfo2合并后的全部sql sync->CN.
@story('sync')
syncStep1
syncStep2
@endstory
@story('deploy')
deploy01
rmQueue
#rmScheduler
@endstory
@story('backup')
backupCN
backupEN
@endstory
#step1 CN备份用户相关表后,导出到sfo2
@task('syncStep1', ['on' => 'qq3'])
cd /var/www/html/lms-abc
FILENAME=lms-abc.sync.$(date '+%Y%m%d%H%M%S').db.backup.sql
docker-compose exec -T db mysqldump -uroot -proot laravel \
users \
socials \
roles \
profiles \
agencies \
contacts \
zooms \
schools \
students \
teachers \
books \
pay_methods \
permissions \
role_has_permissions \
model_has_permissions \
model_has_roles \
audits \
products \
comments \
videos \
votes \
vote_types \
bills > /tmp/$FILENAME \
&& echo 'backed some tables on qq3.' \
&& echo 'sync to sfo2 ...' \
&& scp /tmp/$FILENAME [email protected]:/tmp/ \
&& rm /tmp/$FILENAME \
&& echo 'synced to sfo2 & deleted on qq3.' \
&& ssh [email protected]<< EOF
cd /var/www/html/lms-abc \
&& echo 'import to sfo2 ...' \
&& docker-compose exec -T db mysql -uroot -proot laravel < /tmp/$FILENAME \
&& rclone copy /tmp/$FILENAME 501:/backup/abc/db/sync -v \
&& rm /tmp/$FILENAME \
&& echo 'imported to sfo2 & deleted /tmp/$FILENAME on sfo2.'
EOF
@endtask
#step2 从sfo2合并后的全部sql sync->CN.
@task('syncStep2', ['on' => 'sfo2'])
cd /var/www/html/lms-abc
FILENAME=lms-abc.synced.$(date '+%Y%m%d%H%M%S').db.backup.sql
echo 'backup all tables on sfo2...'
docker-compose exec -T db mysqldump -uroot -proot laravel > /tmp/$FILENAME \
&& echo 'backup all tables done & scp to qq3...' \
&& scp /tmp/$FILENAME [email protected]:/tmp/ \
&& rclone copy /tmp/$FILENAME 501:/backup/abc/db/synced -v \
&& rm /tmp/$FILENAME \
&& ssh [email protected]<< EOF
cd /var/www/html/lms-abc \
&& echo 'synced to qq3 all ...' \
&& docker-compose exec -T db mysql -uroot -proot laravel < /tmp/$FILENAME \
&& rm /tmp/$FILENAME
EOF
@endtask
#1.备份
#2.传输到sfo2上,备份到501drive
@task('backupCN', ['on' => 'qq3'])
cd /var/www/html/lms-abc
FILENAME=cn.lms.abc.$(date '+%Y%m%d%H%M%S').db.backup.sql
echo "Backup On CN begin ..."
echo "scp [email protected]:/tmp/$FILENAME /tmp/ && mysql -uroot abc < /tmp/$FILENAME"
docker-compose exec -T db mysqldump -uroot -proot laravel > /tmp/$FILENAME \
&& echo 'sync to sfo2 ...' \
&& scp /tmp/$FILENAME [email protected]:/tmp/ \
&& echo 'deleted on qq3 ...' \
&& rm /tmp/$FILENAME -rf \
&& echo "Login in SFO2 begin to backup to 501..." \
&& ssh [email protected]<< EOF
echo 'sync to 501 begin...' \
&& rclone copy /tmp/$FILENAME 501:/backup/abc/db/ -v \
&& rm /tmp/$FILENAME -rf \
&& echo 'synced to 501 & deleted backup on SFO2 SUCCESS'
EOF
@endtask
@task('backupEN', ['on' => 'sfo2'])
cd /var/www/html/lms-abc
FILENAME=en.lms.abc.$(date '+%Y%m%d%H%M%S').db.backup.sql
echo "scp [email protected]:/tmp/$FILENAME /tmp/ && mysql -uroot abc < /tmp/$FILENAME"
# --extended-insert=FALSE --complete-insert=TRUE
docker-compose exec -T db mysqldump -uroot -proot laravel > /tmp/$FILENAME \
&& rclone copy /tmp/$FILENAME 501:/backup/abc/db/ -v \
&& rm /tmp/$FILENAME -rf \
&& echo 'synced to 501 & deleted backupEN SUCCESS'
@endtask
@task('deploy01', ['on' => ['sfo2','qq3'], 'parallel' => true])
docker pull guoxiangke/abc
cd /var/www/html/lms-abc
git checkout .
git pull origin master
cat .env | grep DOMAIN
docker-compose down
# 更新代码
docker volume rm lms-abc_code
docker-compose up -d
# docker-compose up -d --build
docker network connect bridge abc-webserver
docker restart abc-webserver a-nginx a-nginx-gen
sleep 30;
docker restart abc-webserver a-nginx a-nginx-gen
docker-compose exec -T app bash -c "
php composer dump-autoload \
&& php artisan clear-compiled \
&& php artisan config:clear \
&& php artisan config:cache \
&& php artisan cache:clear \
&& php artisan route:clear \
&& php artisan view:clear \
&& php artisan view:cache \
&& rm -rf public/storage \
&& php artisan storage:link \
&& chown www-data:www-data storage/app/ -R"
@endtask
@task('rmQueue', ['on' => ['qq3']])
cd /var/www/html/lms-abc
docker-compose stop queue
docker-compose rm -f queue
@endtask
@task('rmScheduler', ['on' => ['qq3']])
cd /var/www/html/lms-abc
docker-compose stop scheduler
docker-compose rm -f scheduler
@endtask
@task('cg', ['on' => 'sfo2'])
cd /var/www/html/lms-abc
docker-compose exec -T app bash -c "
php artisan classrecords:generate 1 --order=2
"
@endtask
@task('backupCN4dev', ['on' => 'qq3'])
cd /var/www/html/lms-abc
FILENAME=cn.lms.abc.$(date '+%Y%m%d%H%M%S').db.backup.sql
echo "Backup On CN begin ..."
echo "scp [email protected]:/tmp/$FILENAME /tmp/ && mysql -uroot abc < /tmp/$FILENAME"
docker-compose exec -T db mysqldump -uroot -proot laravel > /tmp/$FILENAME
@endtask
@task('backupEN4dev', ['on' => 'sfo2'])
cd /var/www/html/lms-abc
FILENAME=en.lms.abc.$(date '+%Y%m%d%H%M%S').db.backup.sql
echo "Backup On CN begin ..."
echo "scp [email protected]:/tmp/$FILENAME /tmp/ && mysql -uroot abc < /tmp/$FILENAME"
docker-compose exec -T db mysqldump -uroot -proot laravel > /tmp/$FILENAME
@endtask