Advertisement
Guest User

Untitled

a guest
May 18th, 2017
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. include('config.php');
  2. include('functions.php');
  3.  
  4. $backupName = "backup-".date('d-m-y H-i-s').'.zip';
  5.  
  6. $createZip = new createZip;
  7.  
  8. if (isset($configBackup) && is_array($configBackup) && count($configBackup)>0)
  9. {
  10.  
  11. // Lets backup any files or folders if any
  12.  
  13. foreach ($configBackup as $dir)
  14. {
  15. $basename = basename($dir);
  16.  
  17. // dir basename
  18. if (is_file($dir))
  19. {
  20. $fileContents = file_get_contents($dir);
  21. $createZip->addFile($fileContents,$basename);
  22. }
  23. else
  24. {
  25.  
  26. $createZip->addDirectory($basename."/");
  27.  
  28. $files = directoryToArray($dir,true);
  29.  
  30. $files = array_reverse($files);
  31.  
  32. foreach ($files as $file)
  33. {
  34.  
  35. $zipPath = explode($dir,$file);
  36. $zipPath = $zipPath[1];
  37.  
  38. // skip any if required
  39.  
  40. $skip = false;
  41. foreach ($configSkip as $skipObject)
  42. {
  43. if (strpos($file,$skipObject) === 0)
  44. {
  45. $skip = true;
  46. break;
  47. }
  48. }
  49.  
  50. if ($skip) {
  51. continue;
  52. }
  53.  
  54.  
  55. if (is_dir($file))
  56. {
  57. $createZip->addDirectory($basename."/".$zipPath);
  58. }
  59. else
  60. {
  61. $fileContents = file_get_contents($file);
  62. $createZip->addFile($fileContents,$basename."/".$zipPath);
  63. }
  64. }
  65. }
  66.  
  67. }
  68.  
  69. }
  70.  
  71. if (isset($configBackupDB) && is_array($configBackupDB) && count($configBackupDB)>0)
  72. {
  73.  
  74. foreach ($configBackupDB as $db)
  75. {
  76. $backup = new MySQL_Backup();
  77. $backup->server = $db['server'];
  78. $backup->username = $db['username'];
  79. $backup->password = $db['password'];
  80. $backup->database = $db['database'];
  81. $backup->tables = $db['tables'];
  82.  
  83. $backup->backup_dir = $configBackupDir;
  84.  
  85. $sqldump = $backup->Execute(MSB_STRING,"",false);
  86.  
  87. $createZip->addFile($sqldump,$db['database'].'-sqldump.sql');
  88.  
  89. }
  90.  
  91. }
  92.  
  93. $fileName = $configBackupDir.$backupName;
  94. $fd = fopen ($fileName, "wb");
  95. $out = fwrite ($fd, $createZip -> getZippedfile());
  96. fclose ($fd);
  97.  
  98. // Dump done now lets email the user
  99.  
  100. if (isset($configEmail) && !empty($configEmail))
  101. {
  102. mailAttachment($fileName,$configEmail,'noreply@gmail.com','Backup Script','noreply@gmail.com','Backup - '.$backupName,"Backup file is attached");
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement