Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. <?php
  2. $datestamp = date("Y-m-d");      // Current date to append to filename of backup file in format of YYYY-MM-DD
  3.  
  4. /* CONFIGURE THE FOLLOWING THREE VARIABLES TO MATCH YOUR SETUP */
  5. $dbuser = "username";      // Database username
  6. $dbpwd = "password";         // Database password
  7. $dbname = "dbname";      // Database name. Use --all-databases if you have more than one
  8. $filename= "changethename.sql.gz";   // The name (and optionally path) of the dump file
  9.  
  10. $command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename";
  11. $result = passthru($command);
  12.  
  13. /* CONFIGURE THE FOLLOWING FOUR VARIABLES TO MATCH YOUR FTP SETUP */
  14. $ftp_server = "FTP IP HERE";   // Shouldn't have any trailing slashes and shouldn't be prefixed with ftp://
  15. $ftp_port = "21";            // FTP port - blank defaults to port 21
  16. $ftp_username = "FTP USERNAME";         // FTP account username
  17. $ftp_password = "PASSWORD";         // FTP account password - blank for anonymous
  18.  
  19. // set up basic connection
  20. $ftp_conn = ftp_connect($ftp_server);
  21.  
  22. // Turn PASV mode on or off
  23. ftp_pasv($ftp_conn, false);
  24.  
  25. // login with username and password
  26. $login_result = ftp_login($ftp_conn, $ftp_username, $ftp_password);
  27.  
  28. // check connection
  29. if ((!$ftp_conn) || (!$login_result))
  30. {
  31.    echo "FTP connection has failed.";
  32.    echo "Attempted to connect to $ftp_server for user $ftp_username";
  33.    exit;
  34. }
  35. else
  36. {
  37.    echo "Connected to $ftp_server, for user $ftp_username";
  38. }
  39.  
  40. // upload the file
  41. $upload = ftp_put($ftp_conn, $filename, $filename, FTP_BINARY);
  42.  
  43. // check upload status
  44. if (!$upload)
  45. {
  46.    echo "FTP upload has failed.";
  47. }
  48. else
  49. {
  50.    echo "Uploaded $filename to $ftp_server.";
  51. }
  52.  
  53. // close the FTP stream
  54. ftp_close($ftp_conn);
  55.  
  56. unlink($filename);   //delete the backup file from the server
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement