~abentley/launchpad/trunk

« back to all changes in this revision

Viewing changes to staging_restore.sh

  • Committer: PostgreSQL administrator
  • Date: 2009-12-16 12:35:25 UTC
  • Revision ID: postgres@sourcherry-20091216123525-18q033qx85n57zkd
[r=elmo][mthaddon] if we aren't updating the code, we don't want to run DB upgrades either, or run nightly processes

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
# anything but True
35
35
PERFORM_DB_IMPORT=True
36
36
 
 
37
# And if you want to skip DB updates altogether, set
 
38
# this to True
 
39
SKIP_DB_UPDATES=False
 
40
 
37
41
# If we want to update regardless of whether there's
38
42
# new code or not, this should be False. Note that if
39
43
# you are skipping DB import as well, it will update
137
141
                        echo $(date) "No schema changes since last update - skip DB restore" >> $LOGFILE 2>&1
138
142
                        CHECK_FOR_DUMPFILE=False
139
143
                        PERFORM_DB_IMPORT=False
 
144
                        SKIP_DB_UPDATES=True
 
145
                        PERFORM_NIGHTLY=False
140
146
                fi
141
147
        fi
142
148
fi
227
233
 
228
234
else
229
235
 
230
 
        # Now we need to update the code and run the upgrade on the DB
231
 
        rsync -a --delete ${SOURCEDIR}/ ${ROOTDIR}/staging/launchpad/
232
 
        cd ${ROOTDIR}/staging/launchpad
233
 
        make build LPCONFIG=staging >> $LOGFILE 2>&1
234
 
        cd ${ROOTDIR}/staging/launchpad/database/schema
235
 
        export LPCONFIG=staging
236
 
        # Kill any connections to the DB. New ones should be stopped by the 
237
 
        # maintenance text files being in place
238
 
        psql -U postgres -d template1 -f ${ROOTDIR}/scripts/kill_staging_connections.sql >> $LOGFILE 2>&1
239
 
 
240
 
        echo $(date) "Applying database updates and permissions to DB" >> $LOGFILE
241
 
        ./upgrade.py -U postgres >> $LOGFILE 2>&1
242
 
        if [ $? != 0 ]; then
243
 
                echo $(date) "ERROR: Failed to run upgrade.py" >> $LOGFILE
244
 
                psql -U postgres -d template1 -c "SELECT * FROM pg_stat_activity" >> $LOGFILE 2>&1
245
 
                cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_master_staging-setup.log \
246
 
                    ${ROOTDIR}/staging-logs/lpslon_main_master_staging-setup.$(date +%Y-%m-%d-%H-%M).log
247
 
                cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_slave_staging-setup.log \ 
248
 
                    ${ROOTDIR}/staging-logs/lpslon_main_slave_staging-setup.$(date +%Y-%m-%d-%H-%M).log
249
 
                echo "Replication logs copied to ${ROOTDIR}/staging-logs" >> $LOGFILE
250
 
 
251
 
                # Let's email it - since it's being run from
252
 
                # cron, just cat-ing the logfile will do this
253
 
                cat $LOGFILE
254
 
 
255
 
                exit $?
256
 
        else
257
 
                echo $(date) "DB upgrades applied" >> $LOGFILE
258
 
        fi
259
 
        ./fti.py -U postgres >> $LOGFILE 2>&1
260
 
        if [ $? != 0 ]; then
261
 
                echo $(date) "ERROR: Failed to run fti.py" >> $LOGFILE
262
 
                psql -U postgres -d template1 -c "SELECT * FROM pg_stat_activity" >> $LOGFILE 2>&1
263
 
                cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_master_staging-setup.log \
264
 
                    ${ROOTDIR}/staging-logs/lpslon_main_master_staging-setup.$(date +%Y-%m-%d-%H-%M).log
265
 
                cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_slave_staging-setup.log \ 
266
 
                    ${ROOTDIR}/staging-logs/lpslon_main_slave_staging-setup.$(date +%Y-%m-%d-%H-%M).log
267
 
                echo "Replication logs copied to ${ROOTDIR}/staging-logs" >> $LOGFILE
268
 
 
269
 
                # Let's email it - since it's being run from
270
 
                # cron, just cat-ing the logfile will do this
271
 
                cat $LOGFILE
272
 
 
273
 
                exit $?
274
 
        else
275
 
                echo $(date) "Full text indexes rebuilt" >> $LOGFILE
276
 
        fi
277
 
        ./security.py -U postgres >> $LOGFILE 2>&1
278
 
        if [ $? != 0 ]; then
279
 
                echo $(date) "ERROR: Failed to run security.py" >> $LOGFILE
280
 
                psql -U postgres -d template1 -c "SELECT * FROM pg_stat_activity" >> $LOGFILE 2>&1
281
 
                cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_master_staging-setup.log \
282
 
                    ${ROOTDIR}/staging-logs/lpslon_main_master_staging-setup.$(date +%Y-%m-%d-%H-%M).log
283
 
                cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_slave_staging-setup.log \ 
284
 
                    ${ROOTDIR}/staging-logs/lpslon_main_slave_staging-setup.$(date +%Y-%m-%d-%H-%M).log
285
 
                echo "Replication logs copied to ${ROOTDIR}/staging-logs" >> $LOGFILE
286
 
 
287
 
                # Let's email it - since it's being run from
288
 
                # cron, just cat-ing the logfile will do this
289
 
                cat $LOGFILE
290
 
 
291
 
                exit $?
292
 
        else
293
 
                echo $(date) "Security applied to DB" >> $LOGFILE
294
 
        fi 
295
 
        ./security.py -U postgres -d lpmain_staging_slave >> $LOGFILE 2>&1
296
 
        if [ $? != 0 ]; then
297
 
                echo $(date) "ERROR: Failed to run security.py on slave" >> $LOGFILE
298
 
                psql -U postgres -d template1 -c "SELECT * FROM pg_stat_activity" >> $LOGFILE 2>&1
299
 
                cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_master_staging-setup.log \
300
 
                    ${ROOTDIR}/staging-logs/lpslon_main_master_staging-setup.$(date +%Y-%m-%d-%H-%M).log
301
 
                cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_slave_staging-setup.log \ 
302
 
                    ${ROOTDIR}/staging-logs/lpslon_main_slave_staging-setup.$(date +%Y-%m-%d-%H-%M).log
303
 
                echo "Replication logs copied to ${ROOTDIR}/staging-logs" >> $LOGFILE
304
 
 
305
 
                # Let's email it - since it's being run from
306
 
                # cron, just cat-ing the logfile will do this
307
 
                cat $LOGFILE
308
 
 
309
 
                exit $?
310
 
        else
311
 
                echo $(date) "Security applied to slave DB" >> $LOGFILE
312
 
        fi 
313
 
 
 
236
        if [ "$SKIP_DB_UPDATES" = "False" ]; then
 
237
 
 
238
                # Now we need to update the code and run the upgrade on the DB
 
239
                rsync -a --delete ${SOURCEDIR}/ ${ROOTDIR}/staging/launchpad/
 
240
                cd ${ROOTDIR}/staging/launchpad
 
241
                make build LPCONFIG=staging >> $LOGFILE 2>&1
 
242
                cd ${ROOTDIR}/staging/launchpad/database/schema
 
243
                export LPCONFIG=staging
 
244
                # Kill any connections to the DB. New ones should be stopped by the 
 
245
                # maintenance text files being in place
 
246
                psql -U postgres -d template1 -f ${ROOTDIR}/scripts/kill_staging_connections.sql >> $LOGFILE 2>&1
 
247
 
 
248
                echo $(date) "Applying database updates and permissions to DB" >> $LOGFILE
 
249
                ./upgrade.py -U postgres >> $LOGFILE 2>&1
 
250
                if [ $? != 0 ]; then
 
251
                        echo $(date) "ERROR: Failed to run upgrade.py" >> $LOGFILE
 
252
                        psql -U postgres -d template1 -c "SELECT * FROM pg_stat_activity" >> $LOGFILE 2>&1
 
253
                        cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_master_staging-setup.log \
 
254
                            ${ROOTDIR}/staging-logs/lpslon_main_master_staging-setup.$(date +%Y-%m-%d-%H-%M).log
 
255
                        cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_slave_staging-setup.log \ 
 
256
                            ${ROOTDIR}/staging-logs/lpslon_main_slave_staging-setup.$(date +%Y-%m-%d-%H-%M).log
 
257
                        echo "Replication logs copied to ${ROOTDIR}/staging-logs" >> $LOGFILE
 
258
 
 
259
                        # Let's email it - since it's being run from
 
260
                        # cron, just cat-ing the logfile will do this
 
261
                        cat $LOGFILE
 
262
 
 
263
                        exit $?
 
264
                else
 
265
                        echo $(date) "DB upgrades applied" >> $LOGFILE
 
266
                fi
 
267
                ./fti.py -U postgres >> $LOGFILE 2>&1
 
268
                if [ $? != 0 ]; then
 
269
                        echo $(date) "ERROR: Failed to run fti.py" >> $LOGFILE
 
270
                        psql -U postgres -d template1 -c "SELECT * FROM pg_stat_activity" >> $LOGFILE 2>&1
 
271
                        cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_master_staging-setup.log \
 
272
                            ${ROOTDIR}/staging-logs/lpslon_main_master_staging-setup.$(date +%Y-%m-%d-%H-%M).log
 
273
                        cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_slave_staging-setup.log \ 
 
274
                            ${ROOTDIR}/staging-logs/lpslon_main_slave_staging-setup.$(date +%Y-%m-%d-%H-%M).log
 
275
                        echo "Replication logs copied to ${ROOTDIR}/staging-logs" >> $LOGFILE
 
276
 
 
277
                        # Let's email it - since it's being run from
 
278
                        # cron, just cat-ing the logfile will do this
 
279
                        cat $LOGFILE
 
280
 
 
281
                        exit $?
 
282
                else
 
283
                        echo $(date) "Full text indexes rebuilt" >> $LOGFILE
 
284
                fi
 
285
                ./security.py -U postgres >> $LOGFILE 2>&1
 
286
                if [ $? != 0 ]; then
 
287
                        echo $(date) "ERROR: Failed to run security.py" >> $LOGFILE
 
288
                        psql -U postgres -d template1 -c "SELECT * FROM pg_stat_activity" >> $LOGFILE 2>&1
 
289
                        cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_master_staging-setup.log \
 
290
                            ${ROOTDIR}/staging-logs/lpslon_main_master_staging-setup.$(date +%Y-%m-%d-%H-%M).log
 
291
                        cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_slave_staging-setup.log \ 
 
292
                            ${ROOTDIR}/staging-logs/lpslon_main_slave_staging-setup.$(date +%Y-%m-%d-%H-%M).log
 
293
                        echo "Replication logs copied to ${ROOTDIR}/staging-logs" >> $LOGFILE
 
294
 
 
295
                        # Let's email it - since it's being run from
 
296
                        # cron, just cat-ing the logfile will do this
 
297
                        cat $LOGFILE
 
298
 
 
299
                        exit $?
 
300
                else
 
301
                        echo $(date) "Security applied to DB" >> $LOGFILE
 
302
                fi 
 
303
                ./security.py -U postgres -d lpmain_staging_slave >> $LOGFILE 2>&1
 
304
                if [ $? != 0 ]; then
 
305
                        echo $(date) "ERROR: Failed to run security.py on slave" >> $LOGFILE
 
306
                        psql -U postgres -d template1 -c "SELECT * FROM pg_stat_activity" >> $LOGFILE 2>&1
 
307
                        cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_master_staging-setup.log \
 
308
                            ${ROOTDIR}/staging-logs/lpslon_main_master_staging-setup.$(date +%Y-%m-%d-%H-%M).log
 
309
                        cp ${ROOTDIR}/staging/launchpad/database/replication/lpslon_main_slave_staging-setup.log \ 
 
310
                            ${ROOTDIR}/staging-logs/lpslon_main_slave_staging-setup.$(date +%Y-%m-%d-%H-%M).log
 
311
                        echo "Replication logs copied to ${ROOTDIR}/staging-logs" >> $LOGFILE
 
312
 
 
313
                        # Let's email it - since it's being run from
 
314
                        # cron, just cat-ing the logfile will do this
 
315
                        cat $LOGFILE
 
316
 
 
317
                        exit $?
 
318
                else
 
319
                        echo $(date) "Security applied to slave DB" >> $LOGFILE
 
320
                fi 
 
321
        fi
314
322
fi
315
323
 
316
324
if [ "$PERFORM_REMOTE" = "True" ]