public function makeBackup()
 {
     $serial_num = BACKUP_LOG::max('serial_num');
     $newSerial_num = sprintf('%08d', $serial_num + 1);
     $currentSerialNum = BACKUP_LOG::find($serial_num);
     $currentSerialNum->serial_num = $newSerial_num;
     $currentSerialNum->save();
     //shell_exec("ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock");
     shell_exec('/Applications/MySQLWorkbench.app/Contents/MacOS/mysqldump   -u' . env('DB_USERNAME') . ' -p' . env('DB_PASSWORD') . ' ' . env('DB_DATABASE') . ' > ' . env('BACKUP_PATH') . $newSerial_num . "_user_backup_`date`" . '.sql');
     // TODO: put this in the constants file
     $path = storage_path() . "/app/Backups/";
     // Search for the required file. Returns matching files.
     $sqldump = File::glob($path . $newSerial_num . '_*.sql');
     $newNotification = new Notifications();
     // TODO: Remove magic numbers
     // TODO: Put messages inside the constants file
     if ($sqldump == false) {
         $newNotification->notification = "Backup Failed!";
         $newNotification->body = "User generated Backup failed.";
         $newNotification->readStatus = '0';
         $newNotification->save();
         Pusher::trigger('notifications', 'failed_notification', ['message' => 'User generated Backup failed.']);
     } else {
         $newNotification->notification = "Backup successful!";
         $newNotification->body = 'Backup #' . $newSerial_num . ' created.';
         $newNotification->readStatus = '0';
         $newNotification->save();
         Pusher::trigger('notifications', 'new_backup_notification', ['message' => 'Backup #' . $newSerial_num . ' created.']);
     }
 }
Пример #2
0
 /**
  * Define the application's command schedule.
  * @link http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     /* $schedule->command('queue:listen')->everyMinute();*/
     /*$schedule->command('inspire')
       ->hourly();*/
     // This scheduled task backs up the db at midnight everyday
     $serial_num = BACKUP_LOG::max('serial_num');
     $newSerial_num = sprintf('%08d', $serial_num + 1);
     $currentSerialNum = BACKUP_LOG::find($serial_num);
     $currentSerialNum->serial_num = $newSerial_num;
     $currentSerialNum->save();
     // This shell command will be executed at Midnight everyday
     $schedule->exec('mysqldump -u' . env('DB_USERNAME') . ' -p' . env('DB_PASSWORD') . ' ' . env('DB_DATABASE') . ' > ' . env('BACKUP_PATH') . $newSerial_num . "_scheduled_backup_`date`" . '.sql')->daily();
     /*// This shell command will be executed at the specified time everyday
       // Test this with php artisan schedule:run
       $schedule->exec('mysqldump -u'.env('DB_USERNAME').' -p'.env('DB_PASSWORD').' '.env('DB_DATABASE').' > '.env('BACKUP_PATH').$newSerial_num."_scheduled_backup_`date`".'.sql')
           ->dailyAt("14:34");*/
     $newNotification = new Notifications();
     $newNotification->notification = "Backup successful!";
     $newNotification->body = 'Backup #' . $newSerial_num . ' created.';
     $newNotification->readStatus = '0';
     $newNotification->save();
 }