#NEWLINE# def db_sync( ) : #NEWLINE# #INDENT# "\n        Synchronise the Database\n        - PostgreSQL support not yet available!\n        - For MySQL, this assumes that /root/.my.cnf is configured on both Test & Prod\n          to allow the root SSH user to have access to the MySQL DB without needing '-u root -p'\n    " #NEWLINE# if ( not ( 'test' in env . host ) ) : #NEWLINE# #INDENT# db_upgrade ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( green ( ( '%s: Synchronising Database' % env . host ) ) ) #NEWLINE# with cd ( '/home/web2py/applications/eden/' ) : #NEWLINE# #INDENT# print ( green ( ( '%s: Dropping old Database' % env . host ) ) ) #NEWLINE# env . warn_only = True #NEWLINE# run ( 'mysqladmin -f drop sahana' , pty = True ) #NEWLINE# env . warn_only = False #NEWLINE# print ( green ( ( '%s: Cleaning databases folder' % env . host ) ) ) #NEWLINE# run ( 'rm -rf databases/*' , pty = True ) #NEWLINE# print ( green ( ( '%s: Creating new Database' % env . host ) ) ) #NEWLINE# run ( 'mysqladmin create sahana' , pty = True ) #NEWLINE# print ( green ( ( '%s: Disabling prepopulate' % env . host ) ) ) #NEWLINE# run ( "sed -i 's/deployment_settings.base.prepopulate = True/deployment_settings.base.prepopulate = 0/' models/000_config.py" , pty = True ) #NEWLINE# #UNINDENT# migrate ( ) #NEWLINE# child = pexpect . spawn ( ( 'ssh -i /root/.ssh/sahana_release %s@%s' % ( env . user , prod_host ) ) ) #NEWLINE# child . expect ( ':~#' ) #NEWLINE# print ( green ( ( '%s: Dumping live' % env . host ) ) ) #NEWLINE# child . sendline ( 'mysqldump sahana > new.sql' ) #NEWLINE# live = '/root/live.sql' #NEWLINE# print ( green ( ( '%s: Transferring live' % env . host ) ) ) #NEWLINE# child . sendline ( ( 'scp -i /root/.ssh/sahana_release new.sql %s@%s:%s' % ( env . user , env . host , live ) ) ) #NEWLINE# child . expect ( ':~#' ) #NEWLINE# child . sendline ( 'exit' ) #NEWLINE# with cd ( '/root/' ) : #NEWLINE# #INDENT# print ( green ( ( "%s: Restoring live to 'old'" % env . host ) ) ) #NEWLINE# env . warn_only = True #NEWLINE# run ( 'mysqladmin -f drop old' , pty = True ) #NEWLINE# env . warn_only = False #NEWLINE# run ( 'mysqladmin create old' , pty = True ) #NEWLINE# run ( 'mysql old < live.sql' , pty = True ) #NEWLINE# #UNINDENT# child = pexpect . spawn ( ( 'ssh -i /root/.ssh/sahana_release %s@%s' % ( env . user , env . host ) ) ) #NEWLINE# child . expect ( ':~#' ) #NEWLINE# child . sendline ( 'cd /home/web2py/applications/eden/static/scripts/tools' ) #NEWLINE# child . expect ( ':/home/web2py/applications/eden/static/scripts/tools#' ) #NEWLINE# child . sendline ( 'python dbstruct_mysql.py' ) #NEWLINE# child . expect ( ':/home/web2py/applications/eden/static/scripts/tools#' ) #NEWLINE# child . sendline ( 'exit' ) #NEWLINE# with cd ( '/root/' ) : #NEWLINE# #INDENT# print ( green ( ( '%s: Dumping fixed data' % env . host ) ) ) #NEWLINE# run ( 'mysqldump -tc old > old.sql' , pty = True ) #NEWLINE# print ( green ( ( '%s: Importing fixed data' % env . host ) ) ) #NEWLINE# run ( 'mysql sahana < old.sql' , pty = True )