Advertisement
Guest User

Backup MySQL Database

a guest
Sep 4th, 2016
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2. //backup database and save as zip.
  3. set_time_limit(1200);// increase time limit for large database
  4. $current_dir = 'db/';//folder where database file should be stored
  5.  
  6. $host = HOSTA;//localhost
  7. $user = USERA;//database username
  8. $pass = PASSA;//database password
  9. $dbname1 = DATAA;//database name
  10.  
  11. $time = time();
  12. $date = date("Ymd");
  13. $randi = rand();
  14. $sql_file_name = "$current_dir/db_backup_"."$randi"."_"."$date"."_$time"."."."sql";//use generated variable to avoid overwriting
  15. exec("C:\wamp\bin\mysql\mysql5.0.51b\bin\mysqldump.exe --user=$user --password=$pass --host=$host $dbname1  > $sql_file_name");//using mysqlidump.exe database dumping feature
  16.  
  17. if (file_exists($sql_file_name)) {
  18. if(extension_loaded('zip')) {
  19. $zip = new ZipArchive(); // Load zip library
  20. $zip_name = "$sql_file_name.zip"; // Zip name
  21. if($zip->open($zip_name, ZIPARCHIVE::CREATE)==TRUE) {
  22. $zip->addFile($sql_file_name);
  23. $zip->close();
  24.  
  25. //force user to download or save to a folder
  26.  
  27.  
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement