Guest User

Untitled

a guest
Mar 22nd, 2018
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3.  
  4. #SSH into the new server, and run this from the home directory. Granted ~/public_html is the Apache DocumentRoot for
  5. #the user
  6.  
  7. import getpass
  8. import os
  9.  
  10. print '\nThis script will automate the process of moving a website from one server to another.'
  11.  
  12. db_name = 'dump'
  13.  
  14. config = {
  15. 'old_ip' : '174.120.168.90',
  16. #db_dump_file_name = 'dump.sql',
  17. 'delete_dump_after_import' : True,
  18. }
  19.  
  20. def ftp_download(config):
  21. print '\nProvide FTP login for old/source server:'
  22. ftp_username = raw_input('FTP Username: ')
  23. ftp_password = getpass.getpass('FTP Password: ');
  24.  
  25. print '\nDownloading public_html folder..'
  26.  
  27. rtrn = 0
  28. rtrn = os.system('wget -m ftp://'+config['old_ip']+'/public_html --ftp-user="'+ftp_username+'" --ftp-password="'+ftp_password+'" --no-host-directories --tries=3')
  29.  
  30. if rtrn != 0:
  31. print '\nFTP download failed with error code', rtrn, ', exiting!'
  32. return
  33.  
  34. print '\nFile transfer finished!'
  35. return
  36.  
  37. def db_download(config):
  38. print '\nDatabase details for source server:'
  39. global db_name
  40. db_name = raw_input('Database Name: ')
  41. db_username = raw_input('MySQL Username: ')
  42. db_password = getpass.getpass('MySQL Password: ')
  43.  
  44. print '\nDownloading db dump, grab a cup of coffee as this may take a while depending upon the db size'
  45. print 'Make sure you have added the current host/ip to remote database acess host list in the server'
  46. os.system('mysqldump -u '+db_username+' --password="'+db_password+'" -h '+config['old_ip']+' '+db_name+' | pv -ptrbe >'+db_name+'.sql')
  47. print '\nDatabase dump download finished!'
  48. return
  49.  
  50. def db_import(config):
  51. print '\nDatabase details for target server:'
  52. new_db_name = raw_input('Database Name:')
  53. new_db_username = raw_input('MySQL Username:')
  54. new_db_pass = getpass.getpass('MySQL Password:')
  55.  
  56. rtrn =0
  57. rtrn = os.system('mysql -u '+new_db_username+' --password='+new_db_pass+' '+new_db_name+' < '+db_name+'.sql')
  58.  
  59. if rtrn != 0:
  60. print '\nDatabase import failed with error code', rtrn, ', exiting!'
  61. return
  62.  
  63. if config['delete_dump_after_import']:
  64. os.remove(db_name+'.sql')
  65. print '\nDatabase dump deleted'
  66.  
  67. print '\nDatabase import successful! Have fun!'
  68. return
  69.  
  70.  
  71. while True:
  72. print '\n\n\n1. Download files with FTP.'
  73. print '2. Download database dump.'
  74. print '3. Import database dump.'
  75. print '4. Exit!\n'
  76. inp = raw_input('Enter your choice: ')
  77. if inp == '1':
  78. ftp_download(config)
  79. if inp == '2':
  80. db_download(config)
  81. if inp == '3':
  82. db_import(config)
  83. if inp == '4':
  84. print '\nBye Bye!\n'
  85. break
Add Comment
Please, Sign In to add comment