daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Oct 17th, 2017 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. import ConfigParser
  3. import os
  4. import time
  5. import getpass
  6.  
  7.  
  8. def combine_files(self,file1,file2):
  9.     with open('file1', 'w') as outfile:
  10.             with open(file2) as infile:
  11.                 for line in infile:
  12.                     outfile.write(line)    
  13.  
  14. def get_dbcopy():
  15.    
  16.     script_dir = os.path.dirname(os.path.realpath(__file__))    
  17.  
  18.     print "Enter origin database user:"
  19.     origin_user = raw_input()
  20.  
  21.     print "Enter origin database password: (Password will not be visible)"
  22.     origin_password = getpass.getpass()
  23.  
  24.     print "Enter origin database host:"
  25.     origin_host = raw_input()
  26.  
  27.     print "Enter origin database: (Which database to dump"
  28.     origin_database = raw_input()
  29.  
  30.     print "Enter destination database user:"
  31.     dest_user = raw_input()
  32.  
  33.     print "Enter destination database password: (Password will not be visible)"
  34.     dest_password = getpass.getpass()
  35.  
  36.     print "Enter destination database host: (leave blank for same host)"
  37.     dest_host = raw_input()
  38.     if(not dest_host):
  39.         dest_host = origin_host
  40.    
  41.     print "Enter destination database name:"
  42.     dest_database = raw_input()
  43.    
  44.     print "Include routines? y/n (leave blank for y)"
  45.     include_routines = raw_input()
  46.    
  47.     if(not include_routines):
  48.         include_routines = "y"
  49.  
  50.  
  51.     filestamp = time.strftime('%Y-%m-%d-%I:%M')
  52.     dump_file = script_dir+"/"+origin_database+"_"+filestamp+".sql"
  53.     if(include_routines.lower() == "y" or include_routines == ''):
  54.         os.popen("mysqldump -u %s --password%s -h %s --default-character-set=utf8 --routines --ignore-table=%s.log %s --result-file $s" % (origin_user,password,origin_host,origin_database,origin_database,dump_file))
  55.     else:
  56.         os.popen("mysqldump -u %s --password%s -h %s --default-character-set=utf8 --ignore-table=%s.log %s --result-file $s" % (origin_user,origin_password,origin_host,origin_database,origin_database,dump_file))
  57.  
  58.    
  59.     print "\n-- The dump file has been created @ "+dump_file+" --"
  60.    
  61.     sql_update_file = script_dir+"/"+database+"_updates.sql";
  62.    
  63.     #if sql_update_file exists combine with sql dump file
  64.     if(os.path.isfile(sql_update_file)):
  65.         print "\n-- combing the dump file with: "+sql_update_file
  66.         combine_files(dump_file,sql_update_file)
  67.        
  68.    
  69.     #import mysql dump file
  70.     os.popoen("mysql -u %s --password%s -h %s --default-character-set=utf8 %s < %s" % (dest_user,dest_password,dest_host,dest_database,dump_file))
  71.    
  72. if __name__=="__main__":
  73.     get_dbcopy()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top