Guest User

Untitled

a guest
Jan 6th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.47 KB | None | 0 0
  1. #Restore_web.py
  2. import os
  3. import subprocess
  4. import sys
  5.  
  6.  
  7. if len(sys.argv) != 2:
  8.     print "Wrong syntax try again:"
  9.     print "python2.7 restore_web.py file.tar"
  10. else:  
  11.     subprocess.check_output("tar xf " + sys.argv[1] + " /home/sitewebs/",shell=True)
  12. #restore_mysql.py
  13. import os
  14. import subprocess
  15. import sys
  16.  
  17. #Run with mysql-2 user
  18.  
  19. if len(sys.argv) != 2:
  20.     print "Wrong syntax try again:"
  21.     print "python2.7 restore_mysql.py file.sql"
  22. else:  
  23.     subprocess.check_output("mysql-2 <"+sys.argv[1],shell=True)
  24. #Mysql_dump.py
  25. #Writed by Hayicle
  26. #/usr/bin/env python
  27.  
  28.  
  29. #Solution backup databases
  30.  
  31. #password mysql 7cbhcDu5K
  32.  
  33. import os
  34. import subprocess
  35. from datetime import datetime
  36.  
  37.  
  38. #Check directory exist or not
  39. def check_dir_exist(os_dir):
  40.     if os.path.exists(os_dir):
  41.         return True
  42.     else:
  43.         return False
  44.  
  45. #dump databases with mysqldump 
  46. def dump_databases(name,time):
  47.     subprocess.check_output("mysqldump --all-databases --set-gtid-purged=OFF --triggers --routines --events > backup_"+name+time+".sql",shell=True)
  48.  
  49. #Change dir and dump databases file
  50. def change_dir(os_dir):
  51.     time = datetime.now().strftime("%Y-%m-%d")
  52.     if check_dir_exist(os_dir)==False:
  53.         subprocess.check_output("mkdir -p " + os_dir ,stderr=subprocess.STDOUT,shell=True)
  54.     os.chdir(os_dir)
  55.    
  56.     dump_databases('-dump-databases-',time)
  57.    
  58.    
  59.  
  60.    
  61. def main():
  62.     subprocess.check_output("mkdir -p -m 777 /home/backup/databases",shell=True)
  63.     change_dir('/home/backup/databases')
  64.    
  65.    
  66. main()
Advertisement
Add Comment
Please, Sign In to add comment