Guest User

Untitled

a guest
Oct 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <?php
  2.  
  3. /*======================================
  4. = PHP MySQL Backup =
  5. ======================================*/
  6.  
  7. if(function_exists('exec'))
  8. {
  9.  
  10. // Back-up folder
  11. $folder_to_backup = "/path/to/folder";
  12. $backup_folder = "/path/to/backup/folder";
  13. exec("tar -cvf $backup_folder/backupfile.gz $folder_to_backup/* --exclude='$folder_to_backup/*.gz'", $results, $result_value);
  14. if ($result_value == 0){
  15. echo "The archive has been successfully created!";
  16. } else {
  17. echo "Archive creation failed!";
  18. }
  19.  
  20. // Back-up MySql database
  21. $mysql_host = "localhost";
  22. $mysql_user = "username";
  23. $mysql_pass = "password";
  24. $mysql_database = "my_database";
  25. $backup_folder = "/path/to/backup/folder";
  26.  
  27. exec("mysqldump -h $mysql_host -u $mysql_user -p$mysql_pass $mysql_database > $backup_folder/my-sql-backup.sql", $results, $result_value);
  28. if ($result_value == 0){
  29. echo "The MySql backup successfully created!";
  30. } else {
  31. echo "MySql backup creation failed!";
  32. }
  33.  
  34. }
  35.  
  36. /*===== PHP MySQL Backup ======*/
  37.  
  38. ?>
Add Comment
Please, Sign In to add comment