Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

spatie/laravel-backup : list of the backups

Hello,

I discover this Spatie package, all works fine, but when I run the backup:list command, it doesn't show the list of the backups, I mean if I have done 3 backups for an app, it shows me only one line saying that I have 3 backups. I thought the list command would have returned the list of the backup files so that I could display them on the screen and setting links to download them.

So the only way to really retrieve the list of the backups is to read the content of the backup folder with the PHP basic commands ?

Or perhaps I haven't understood the spatie commands or bad read the documentation ?

If you have any details ;).

Thanks.

V

0 likes
7 replies
jlrdw's avatar
jlrdw
Best Answer
Level 75

The first line of code in that class is:

if (config()->has('backup.monitorBackups')) {

So reread how to setup your config options.

FYI it's much easier just dumping the DB via mysql. In the background it's done the same.

2 likes
vincent15000's avatar

@jlrdw Yes I wanted to test the package, I had done my own backup code and it worked fine too ;).

Hmmm ... where are you seeing this line ? I've just searched for that string in the spatie code and I don't find anything.

vincent15000's avatar

@jlrdw Ok thank you, I have to learn how to explore the source code of packages, I really rarely do that.

But I don't speak about the list of apps backuped, but the number of backups for one app.

For example I run 5 times the command php artisan backup:run, and I'd like to display a list with the 5 backup zip files. I have done this very simply with Storage::disk('backups')->files('directory');.

I just thought that the spatie package would have a command to list each backup files for one app ;).

1 like
vincent15000's avatar

@jlrdw Oh ok ... No I don't use spatie/laravel-backup-server but spatie/laravel-backup. These are quite different packages.

vincent15000's avatar

@jlrdw I have it work fine. But I decided to go back to my own backup code.

$username = config('database.connections.mysql.username');
$password = config('database.connections.mysql.password');
$database = config('database.connections.mysql.database');

$zipfile = storage_path('backups').'/'.date('Ymd-His').'.zip';

$zip = new \ZipArchive();
$zip->open($zipfile, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);

// Backup des medias
$path = storage_path('app/medias');
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
foreach ($files as $name => $file)
{
    if (!$file->isDir()) {
        $filePath = $file->getRealPath();
        $relativePath = explode('app/medias/', $filePath)[1];
        $zip->addFile($filePath, $relativePath);
    }
}

// Backup de la base de données
$databasefile = storage_path('backups').'/'.date('Ymd-His').'.sql';
$exploded = explode('/', $databasefile);
$databasefilename = $exploded[count($exploded) - 1];

$commande = 'mysqldump --no-tablespaces --user='.$username.' --password='.$password.' --databases '.$database.' > '.$databasefile;
shell_exec($commande);

$zip->addFile($databasefile, $databasefilename);

$zip->close();

unlink($databasefile);
1 like

Please or to participate in this conversation.