Blogger Information
Blog 10
fans 0
comment 0
visits 7011
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Laravel实现备份数据库以及下载和删除备份文件
礼物粑粑
Original
351 people have browsed it

话不多说,直接上代码

1 备份,定好路径,这里定义的路径是项目的storage/app/public/backup,然后直接调用下面方法即可

  1. $dirPath = storage_path('app/public/backup/');
  2. if (!file_exists($dirPath)) mkdir($dirPath);
  3. $filePath = $dirPath.date('Y-m-d').'_'.date('H:i:s').'.sql';
  4. $database = sprintf(
  5. 'mysqldump -h%s -p%s -u%s -p%s %s > %s',
  6. env('DB_HOST'),
  7. env('DB_PORT'),
  8. env('DB_USERNAME'),
  9. env('DB_PASSWORD'),
  10. env('DB_DATABASE'),
  11. $filePath
  12. );
  13. $process = new Process($database);
  14. $process->mustRun();

2 查询,下载,删除

  1. Storage::disk('public')->allFiles('/backup');
  2. Storage::disk('public')->download('/backup/xxxx.sql');
  3. Storage::disk('public')->delete('/backup/xxxx.sql');

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post