Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel backup

composer require spatie/laravel-backup
//To publish the config file to config/backup.php
php artisan vendor:publish --provider="SpatieBackupBackupServiceProvider"
//Once installed run 
php artisan backup:run
//clean up your backups
php artisan backup:clean
//Determining which backups should be deleted is mention in config/backup.php
Comment

how to backup laravel project with database

//First install laravel spatie using following commands
composer require spatie/laravel-backup
php artisan vendor:publish --provider="SpatieBackupBackupServiceProvider"

//now in config/backup.php file replace replace 
relative_path = null, 
  to
relative_path= base_path(),

//now add this code inside config/database.php
'connections' => [
	'mysql' => [
		'driver'    => 'mysql'
		...,
		'dump' => [
                'dump_binary_path' => 'C:xamppmysqlin', // only the path, so without `mysqldump` or `pg_dump`
                'use_single_transaction',
                'timeout' => 60 * 5, // 5 minute timeout
                'exclude_tables' => ['table1', 'table2'
                ],             ]
	],
//now run following command to generate backup of project with database
php artisan backup:run
//you can find the backup files inside storageapp
Comment

laravel backup

composer require spatie/laravel-backup
Comment

laravel database backup

<?php

namespace AppHttpControllers;

use Alert;
use AppHttpRequests;
use Artisan;
use Log;
use Storage;

class BackupController extends Controller
{
    public function index()
    {
        $disk = Storage::disk(config('laravel-backup.backup.destination.disks')[0]);

        $files = $disk->files(config('laravel-backup.backup.name'));
        $backups = [];
        // make an array of backup files, with their filesize and creation date
        foreach ($files as $k => $f) {
            // only take the zip files into account
            if (substr($f, -4) == '.zip' && $disk->exists($f)) {
                $backups[] = [
                    'file_path' => $f,
                    'file_name' => str_replace(config('laravel-backup.backup.name') . '/', '', $f),
                    'file_size' => $disk->size($f),
                    'last_modified' => $disk->lastModified($f),
                ];
            }
        }
        // reverse the backups, so the newest one would be on top
        $backups = array_reverse($backups);

        return view("backup.backups")->with(compact('backups'));
    }

    public function create()
    {
        try {
            // start the backup process
            Artisan::call('backup:run');
            $output = Artisan::output();
            // log the results
            Log::info("BackpackBackupManager -- new backup started from admin interface 
" . $output);
            // return the results as a response to the ajax call
            Alert::success('New backup created');
            return redirect()->back();
        } catch (Exception $e) {
            Flash::error($e->getMessage());
            return redirect()->back();
        }
    }

    /**
     * Downloads a backup zip file.
     *
     * TODO: make it work no matter the flysystem driver (S3 Bucket, etc).
     */
    public function download($file_name)
    {
        $file = config('laravel-backup.backup.name') . '/' . $file_name;
        $disk = Storage::disk(config('laravel-backup.backup.destination.disks')[0]);
        if ($disk->exists($file)) {
            $fs = Storage::disk(config('laravel-backup.backup.destination.disks')[0])->getDriver();
            $stream = $fs->readStream($file);

            return Response::stream(function () use ($stream) {
                fpassthru($stream);
            }, 200, [
                "Content-Type" => $fs->getMimetype($file),
                "Content-Length" => $fs->getSize($file),
                "Content-disposition" => "attachment; filename="" . basename($file) . """,
            ]);
        } else {
            abort(404, "The backup file doesn't exist.");
        }
    }

    /**
     * Deletes a backup file.
     */
    public function delete($file_name)
    {
        $disk = Storage::disk(config('laravel-backup.backup.destination.disks')[0]);
        if ($disk->exists(config('laravel-backup.backup.name') . '/' . $file_name)) {
            $disk->delete(config('laravel-backup.backup.name') . '/' . $file_name);
            return redirect()->back();
        } else {
            abort(404, "The backup file doesn't exist.");
        }
    }
}
Comment

database and files backup laravel

// app/Console/Kernel.php

protected function schedule(Schedule $schedule)
{
   $schedule->command('backup:clean')->daily()->at('01:00');
   $schedule->command('backup:run')->daily()->at('01:30');
}
Comment

database and files backup laravel

php artisan vendor:publish --provider="SpatieBackupBackupServiceProvider"
Comment

PREVIOUS NEXT
Code Example
Php :: get the selected value of dropdown php 
Php :: php class extends two classes 
Php :: codeigniter crud generator 
Php :: ereg function in php 
Php :: if php 
Php :: define multiple variables in one line php 
Php :: php run command windows 
Php :: download html table to excel 
Php :: php print number 
Php :: check if is the last day of the month php 
Php :: how to create object in php 
Php :: laravel join 2 tables eloquent 
Php :: laravel validation date time format 
Php :: return last inserted id mysql opencart 
Php :: string to lowercase accentuation hyphenated 
Php :: link headers disabled wp 
Php :: How to find data in other row with laravel-excel 
Php :: Mirror Inverse Program in php 
Php :: Code début Selenium PHP 
Php :: laravel nova create resource 
Php :: verify laravel string must be null 
Php :: codeigniter validate integer in php 
Php :: pass variable in laravel ancher tag laravel 8 
Php :: How to validate Envato Purchase Code in PHP 
Php :: implement class in autoloader athow to implment data table in laravel project 
Php :: php code for english translation optin 
Php :: exists:categories,id except a value laravel 
Php :: laravel upsert always inserting 
Php :: remove database in codeigniter 
Php :: To enqueue css & js quickly 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =