Guest User

Untitled

a guest
Aug 24th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/usr/bin/env python
  2. """
  3. Title: WordPress backup script
  4. """
  5. import sys,os,statvfs
  6. import tarfile
  7. import time
  8. # --- Variables --- #
  9. backup_path = '/home/eklhenam/backup'
  10. source_directorie = '/var/www/html/my-site-name'
  11. todays_date = (time.strftime("%d-%m-%Y"))
  12. free_space_needed = 1000000
  13. backup_site_name = 'my-site-name'
  14. database_name = 'mysitedb'
  15. target_dir = '/home/eklhenam/backup'
  16. username = 'myusername'
  17. password = 'mypassword'
  18. ######################
  19. # --- Check to make sure backup directory has enough space ---#
  20. def check_space_for_backup():
  21. size = os.statvfs(backup_path)
  22. free_space=(size.f_bavail * size.f_frsize) / 1024
  23. return free_space
  24. # --- Backup web root --- #
  25. def backup_webroot():
  26. os.system("tar -zcvf "+target_dir+todays_date+backup_site_name+".tar.gz "+source_directorie)
  27. # --- Backup sql database --- #
  28. def backup_database():
  29. os.system("mysqldump -u "+database_name+" -p"+password+" "+database_name+" > "+target_dir+todays_date+database_name+".sql")
  30. # --- MAIN --- #
  31. def main():
  32. if check_space_for_backup() > free_space_needed:
  33. backup_webroot()
  34. #backup_database()
  35. if __name__ == '__main__':
  36. main()
Add Comment
Please, Sign In to add comment