doing some reading online in the laravel community and searching the internet for laravel backup, I see a whole lot of people using Spatie\Backup with laravel. artisian/composer stuff irks me more often than not ... so I want to do this entirely with Linux tools and the CLI.

Is backing up and restoring really that different with Laravel, compared to say, phpfox v3 or v4?
Can I simply tar up the webroot where the site lives, and grab a dump of the database? Will this restore properly?
I suppose the best way is to just try it and I likely will just to say I've been there and done that.

Anyone else have experience with recoverable backups and Laravel?

ideally I would dump the database to a file, and then use tar to create a compressed archive file with the whole site contained within. Restores should be pretty simple, if this method works. Not much different from the backup/restore methods I've used in the past for sites regardless of the framework. This works for WordPress, Magneto and plain ol' LAMP stack stuff in general.

mysqldump -u phpfox -p'myphpfoxdbpassword' phpfox > phpfox.sql
tar -czf abackupfilename.tar /var/www/html/ phpfox.sql 

I am aware that this could consume a good bit of hard drive space, depending on the database and what users have done on the site. But I need recoverable backups. 

At least I know if I break something tinkering, I can get the site back to the exact state it was in before I started screwing around with settings or system level updates.

Topics: backup, restore

There is nothing really special to this, if you have SSH access to server just backup/restore using your old methods with Linux tools which I think are better than installing additional Laravel packages.

There is nothing really special to this, if you have SSH access to server just backup/restore using your old methods with Linux tools which I think are better than installing additional Laravel packages.



Awesome! that's exactly what I was hoping for!!! Thanks for confirming Stepee!

Be the first person to like this.

Well, well, well ...
I have a working backup that I can restore! Yippie!
There is a gotcha that I'm working through ... and I have a MetaFox feedback ticket open with the phpFox folk to inquire.
The cache directory is positively GIGANTIC!!! So far, clearing file cache data in the AdminCP isn't clearing it.
A fresh site with only me tinkering and playing around posting stuff, shouldn't be over eight GB!
I haven't tried any Laravel CLI options to try and clean out that cache data yet, just being super careful until I hear back from the phpFox folk.

If that vcs directory in the cache can't be cleared, this isn't going to be an option.

I dumped the database first, then created an archive file with tar of the webroot and the database dump file.
Compression of the backup doesn't even help one iota?! Must be a whole bunch of binary data ...

However, with that said ... it's a recoverable backup! All I had to do is drop it on a fresh server, and untar it.
Maybe she's born with it? Maybe it's Maybelline?

here's what I did:
mysqldump -u phpfox -p'phpfoxpassword' phpfox > phpfox.sql
tar -zcf metafox.tar /var/www/html/ phpfox.sql

That's it!
Successful restore takes a bit more work, since you have to drop the database, create the database and then re-apply priviledges for your DBuser. Still ... it works!
tar -zxf metafox.tar.Z /var/www/html/
mysql -u phpfox -p'phpfoxpassword' phpfox < phpfox.sql

Permissions should remain intact with tar however my next effort is secure laravel permissions anyways.

many thanks to Stepee for letting me know I can do this with all the usual backup/restore tools in Linux!
props and thanks Stepee!

More to come once I find out what the deal is with that cache/vcs directory is all about.

Last update on December 1, 2022 by t3ln3t.

Heard back from the phpFox folk ... safe to exclude the cache directory. Thanks Paul! Wheew!!!
Recoverable backups work! The finished process results in a compressed backup that is barely over 127MB. That's perfectamundo!!!
It should grow larger with users, but that's not a problem ... yet!

Super basic but it works!

After dumping the database to a file, I'm using tar to create an archive (minus the cache directory) of the MetaFox install.
mysqldump phpfox > phpfox.sql
tar zcf /root/metafox-$(date +"%Y-%m-%d").tar.gz --exclude /var/www/html/cache --gzip /var/www/html phpfox.sql

I'm running a super simple script from cron daily to get it all backed up correctly. I'll have to modify it in the future
but it's an inital work. Here's the crontab entry in root's crontab:
30 06 * * * /root/metafox_backup.sh > /dev/null 2>&1

If you're interested in the script itself, you're welcome to it. Make sure you set executable permissions with chmod +x metafox_backups.sh
https://short.thesillybus.online/t3ln3t/metafox_backup.sh

aaannnndddd that's why I made sure I have recoverable backups before tinkering! 
tried to do something before doing one iota of homework and broke my alpha playground.

So restores ... it's super simple. Blow away your top level site folder and then copy in the backup.
it's a tar archive, so whatever permissions were applied before should be intact when it's restored.

I got the "oops ... something went wrong" white page when I tried to apply the beta code, first pass.
Probably something I did, but we'll see? Anyways, had to restore finally. I left the DB untouched since the site
hadn't done a tinkle's darn thing. After putting the backup back up, I went through and did stuff on the site just to make sure.

here's exactly what I did to restore from the backup created above this time. Eventually I'll get around to doing it in the script too I guess ...

# mkdir metafox-restore
# cd metafox-restore
# gunzip -c ../metafox-2022-12-08.tar.gz | tar xf -
# cd /var/www/html/
# rm -rf *
# cd /root/metafox-restore
# cp -Rp * /var/www/html/
# php artisian cache:clear

It's icky and needs refinement. PLEASE!?! FOR THE LOVE OF ALL THINGS CUTE & CUDDLY be super duper careful doing stuff on your server! This has the dreaded rm -rf * command and that's the root of all evil. The peril that lies ahead may be too much for you. In that case, get your hosting support folks to help, get the phpfox folks to help or just don't do it!
Eventually folks will do a fancy backup/restore thingie like there is for v4 and it will make what I did look silly.

but there ya' go! backups and restores for MetaFox!

P.S. nobody told me to do the php artisian cache:clear command, I'm just throwing that in all by myself.
Other laravel sites I've run in the past needed that after anything was done too, so I'm just adding it.
It doesn't seem to throw any errors anywhere though ...?

Be the first person to like this.