Installing Laravel Backup0:01
With this next package, I really hope that you already use it, but just to make sure I'm going to introduce it here, it's Laravel Backup by Sparcy. So this is the documentation page of Sparcy's Laravel Backup package, and as you can already see, there is a lot. Again, this is a big package with everything that it can do, but yeah, it's very easy to set up, and this is what we're going to do right now. So we're already here on the installation and setup process, and we're starting by bringing this package into our application.
Reviewing Backup Config0:29
So we're already here on the installation and setup process, and we're starting by bringing this package into our application. All right, and let's also publish the config file. Here we go. Let's bring up the config file, and let's take a look together. You can already see that this is huge, so there's a lot of things that you can define here, but let's take a look at the most important ones. So here you have a name for your backup, which I usually don't care that much.
So here you have a name for your backup, which I usually don't care that much. Mostly it's the app name, like what we have here. So our name would be for the backup Laravel small packages, and what should be included, what should be excluded, if we want to follow links, and let's go down here. So where do we have the most important thing? Yeah, which database we're using, and destination. So this is the most important thing, because we want to make sure where we're going to put our backup.
Running Local Backup1:26
So this is the most important thing, because we want to make sure where we're going to put our backup. By default, it's being stored in the storage folder. Let's maybe try this first. So let's run this with php artisan backup:run. This is going to make the whole backup, and now let's take a look if we can find this. I think it's somewhere here, storage/app. Yeah, this is the one. So here under our application name, we got now a new backup.
Yeah, this is the one. So here under our application name, we got now a new backup. Here it is, everything is set already. But of course, it doesn't make that much sense to put the backup in the same application as the application that you want to backup, because we want to make it secure, we want to make sure that we have access to it, even though our server breaks or something like that. So that's why I often like to provide my backups to another server.
Configuring FTP Storage2:11
even though our server breaks or something like that. So that's why I often like to provide my backups to another server. And I like to do this via FTP. So let's check here. Yeah, so this is where we define the disk, so where our backup is being stored, and this is set to local, and this is why we have this inside our storage folder. But yeah, since this is working with levels, files, and disk system, we can just define any place we want to put our backup.
But yeah, since this is working with levels, files, and disk system, we can just define any place we want to put our backup. So let's go to the file system settings here, and here's where we have defined our disks. And as you can see, this is the local one which we have just used. There are already a few others that you already know. You can also send it to S3 and other destinations, but I want to do this via FTP, because I got another server where I want to put this. All right, so this is how this looks like.
because I got another server where I want to put this. All right, so this is how this looks like. I named this backup, this new disk. I want to use an FTP driver. I'm not providing the host here for you to see. I will do this later. And then I'm going to need a username and a password, which I'm going to use directly from my .env file. All right, now that I have set my host and my credentials for my FTP server, we can try to run it again.
All right, now that I have set my host and my credentials for my FTP server, we can try to run it again. And let's see what we get now. Oh, it's still the same local disk, because we haven't changed the disk yet. So let's do this together. Under settings here, now we're going to use the new backup disk, which we just created. And one more time.
Installing FTP Adapter3:44
which we just created. And one more time. This should take a little bit longer. Okay, we get an error. Let's see what this is about. Oh, yeah, so we want to use an FTP adapter, but we don't have installed this yet. So this is a package that we need from league/flysystem that we need to use in order to use this FTP adapter. So let's install this package as well.
that we need to use in order to use this FTP adapter. So let's install this package as well. That's called leagflysystem. Let's bring this in here, and then we're ready to try it again. All right, run the backup again. And now it takes a little bit longer because it's using FTP to send it to our destination, but it shouldn't take that long. Let's see.
but it shouldn't take that long. Let's see. Successful copy to disk backup complete. And here we go. So now we got a backup of our application, of our full application on a different server, which I think is just great. And yeah, how long did it took us to do this? I don't know, just a couple of minutes. And we have this package set up, ready to go,
Setting Up Notifications4:43
I don't know, just a couple of minutes. And we have this package set up, ready to go, and this is really nice. Also, what we haven't talked about yet, also inside our config file, we have notifications. Here we go. So our different notifications, which are being sent, if the backup has failed, if the cleanup has failed.
if the backup has failed, if the cleanup has failed. So for specific use cases, we see some notifications. By default, they are all set to mail. And since I have already set up my mail in my config file, in my .env file, I have set this up to use a package called Halo, an application called Halo by BeyondCode. So let's take a look at this one. This is the package here.
So let's take a look at this one. This is the package here. And as you can see, we have already received some notification, which normally would have been sent to my real email address if I have set this. But since I'm using the details for this application here, we see that we have received those emails here, those notifications here, to let us know that the backup was successful, which is always a good idea to know about this.
Scheduling Backup Commands5:42
to let us know that the backup was successful, which is always a good idea to know about this. Nice. So this is also working. Let's go back here. What else do I want to show you? Yeah, normally you don't want to run this backup command manually. So we want to set this up inside our ConsoleKernel. And what we can do here, you will also find this inside the documentation of the package that we want to run a backup:clean command every time, every day,
you will also find this inside the documentation of the package that we want to run a backup:clean command every time, every day, just to make sure, because you can define how long you want to keep specific backups. And if they're older, then this package will also delete them, which is nice. And then we also want to run the backup itself every day. For example, that's what I mostly do. And also what I mostly do is I only want to backup the database. Awesome. So again,
And also what I mostly do is I only want to backup the database. Awesome. So again, this package is amazing because it's so easy to install, just a little steps that you have to take and then you're ready to go and your application will be backed up every day. And yeah, that's super cool and easy to do with this package. But as I mentioned, of course, this package is in the end quite a big package because it provides so many other things. So let's see, what do we got here?
Exploring Extra Features6:55
because it provides so many other things. So let's see, what do we got here? There's some kind of monitoring, which we can do for the health of our backups. There are notifications we already talked to, customizing notifiable, so a lot of things that you can customize, extra files, so maybe you want to provide extra files to the backup as well. So yeah, a lot of things that you can do and yeah,
so maybe you want to provide extra files to the backup as well. So yeah, a lot of things that you can do and yeah, check it out for yourself, what you're going to need for this package. But again, I think it's so cool because it's so easy to set up and I use this in every of my applications. Let's break down what you just learned. Whenever you work on an application that is important to you and you put it out into the world, please make sure to also do backups.
and you put it out into the world, please make sure to also do backups. Thank you Spassi for LavalBackup.
