SystemBackup.php
Go to the documentation of this file.
1 <?php
2 
3 namespace App\Console\Commands;
4 
6 
7 class SystemBackup extends Command {
8 
14  protected $name = 'snipeit:backup';
15 
21  protected $description = 'This command creates a database dump and zips up all of the uploaded files in the upload directories.';
22 
28  public function __construct()
29  {
30  parent::__construct();
31  }
32 
38  public function fire()
39  {
40  //
41  $files['avatars'] = glob(public_path().'/uploads/avatars/*');
42  $files['models'] = glob(public_path().'/uploads/models/*');
43  $files['suppliers'] = glob(public_path().'/uploads/suppliers/*');
44  $files['private_uploads'] = glob(config('app.private_uploads').'/*');
45  $base_filename = date('Ymdgis');
46  $zip_file = config('app.private_uploads').'/backups/zips/'.$base_filename.'-backup.zip';
47  $db_dump = config('app.private_uploads').'/backups/sql/'.$base_filename.'-db.sql';
48  $this->call('db:backup', array('filename' => $db_dump));
49  echo $zip_file."\n";
50  echo $db_dump."\n";
51 
52 
53  Zipper::make($zip_file)
54  ->folder('avatars')->add($files['avatars'])
55  ->folder('models')->add($files['models'])
56  ->folder('suppliers')->add($files['suppliers'])
57  ->folder('private_uploads')->add($files['private_uploads'])
58  ->folder('database')->add($db_dump)->close();
59 
60  $this->info('Backup file created at '.$zip_file);
61  $this->info('Removing SQL dump at '.$db_dump);
62  unlink($db_dump);
63 
64  }
65 
66 
67 
68 }
__construct()
Create a new command instance.
fire()
Execute the console command.