Pro Yearly is on sale from $80 to $50! »

Backing up with Laravel

Backing up with Laravel

Thanks to all the excellent resources on server management many developers are now setting up and administrating their own servers. If you are one of them you can't count on anybody else but yourself to backup the data of your clients.
We'll cover the backup issues presented when using modern hosting such as Linode and DigitalOcean. Then we'll review some enterprise grade solutions. Finally we'll dive deep into implementing a backup system using Laravel 5's filesystem abstraction.

A1b4b398630bbd32b77a82cbc37fae9a?s=128

Freek Van der Herten

June 30, 2016
Tweet

Transcript

  1. Backing up 
 with 
 Laravel

  2. About me Freek Van der Herten Partner & developer at

    SPATIE @freekmurze https://murze.be
  3. Since 2003 Websites, applications and webshops Team 4 developers, 1

    manager Specialisation Laravel development
  4. Open source software

  5. Open source software We use a lot of it Nginx,

    Laravel, Ubuntu, Elasticsearch, Memcached, Redis, Beanstalkd, MySQL, Composer, Glide, Homestead, Flysystem, Fractal, Carbon, PHPUnit, NPM, React, jQuery, Java, SSH, Sequel Pro, BackupPC … Basically everything listed in composer.json and package.json
  6. ± 80 packages on Packagist + 600 000 downloads A

    lot of benefits: learning, forced to write documentation and tests, showing the quality of our work, easy updating of client projects https://spatie.be/opensource We create a lot of it Open source software
  7. Laravel Permission Laravel Analytics 
 Laravel Responsecache Laravel Medialibrary Open

    source software
  8. Associate users with roles and permissions Laravel Permission $role =

    Role::create(['name' => 'writer']); $role->givePermissionTo('edit articles'); $user->assignRole('writer'); $user->can('edit articles'); //returns true
  9. Retrieve Google Analytics data Laravel Analytics Analytics::getMostVisitedPages();
 Analytics::getTopBrowsers();
 Analytics::getNumberOfActiveUsers();


  10. Speed up your application 
 by caching the entire response

    Laravel Responsecache RESPONSE CACHE REQUESTS APP 1 2
  11. Associate files with Eloquent Models Laravel Medialibrary $newsItem->addMedia($file)
 ->toCollection(‘images’); $newsItem->getMedia('images')->first()->getUrl();

    $newsItem->getMedia('images')->first()->getUrl('thumb'); $newsItem->addMedia($bigFile)
 ->toCollectionOnDisk('downloads', 's3');
  12. Log the activities of your users Convert addresses to coordinates

    A middleware to check authorization Get notified when a queued job fails Generate pretty url's for paginated pages Check if all links in your app work Integrate Glide with Laravel Subscribe users to MailChimp newsletters A Fractal service provider for Laravel 5 and Lumen Associate users with roles and permissions Store and retrieve objects from Algolia or Elasticsearch Convert PHP 7 code to PHP 5 Fetch the entire trust chain for an SSL certificate Create and validate signed URLs with a limited lifetime Plug-and-play node.js events integration to emit change events A Pjax Middleware for Laravel Make your Eloquent models translatable
  13. https://spatie.be/opensource/laravel

  14. There is no 
 one size fits all solution for

    backups
  15. Small sites Shared hosting Backups by hosting provider Did not

    do anything regarding backups ourselves Hosting Up until a few year ago
  16. Bigger applications Learned server management through resources like serversforhackers.com, Forge

    Digital Ocean Hosting How we are currently doing it
  17. Horror stories

  18. Horror Story #1 Earlier today, our Cloud Operations team was

    alerted to some performance issues affecting the physical server that hosts your droplet. … The damage was serious enough that this droplet was lost and not able to be restored. One fine morning I got this mail from Digital Ocean Full story: https://murze.be/2016/02/today-digitalocean-lost-our-entire-server/
  19. Horror Story #2 This message is a follow-up to our

    previous emails. Despite the very best efforts of our engineering and datacenter operations teams, unfortunately the host machine that your cloud server resides on was not able to be recovered. At this point, there is complete data loss on the server. Horror can occur everywhere. A mail from Rackspace: Source: https://news.ycombinator.com/item?id=3982571
  20. Ok, I’ll just use
 the backup service 
 from my

    cloud provider
  21. Horror Story #3

  22. Horror Story #3

  23. Relying on DO backups 
 is not enough! Only weekly

    snapshots Potentially a lot of data could get lost All the backups in the same datacenter If Digital Ocean is down backups can’t be accessed
  24. Solutions

  25. https://ottomatik.io/ BackupPC Bacula Solutions Do not put your eggs in

    one basket
  26. Backups as a service Not free Install Ottomatik Server Agent

    on every server Easy to use interface Bring your own storage Ottomatik.io
  27. Open source software Installed onto a control server SSH’s into

    servers to be backed up Uses hard links to save disk space Some system administration knowledge is required to setup up BackupPC SERVERS BackupPC SSH
  28. Laravel Backup

  29. Backup files and databases to one or more filesystems Cleanup

    old backups Sending notifications Easily installed into any Laravel application Laravel Backup
  30. None
  31. Backup files & databases FILES DATABASE SERVER S3 DROPBOX DB

    DUMP .ZIP .SQL
  32. Backups use a lot of storage Artisan task to clean

    up old backups Will never delete the youngest backup Fully configurable Grandfather-father-son rotation scheme Cleanup old backups
  33. Grandfather-father-son rotation scheme FEW TIMES A DAY DAILY (16) WEEKLY

    (8) MONTHLY (4) YEARLY(2)
  34. Detects when no backups were made in a certain amount

    of days Detects if there is too much storage used Fully configurable Monitor backups
  35. On (un)successful events (backup failed, youngest backup is too old,

    backup uses too much storage …) Mail, Slack, Pushover Fully configurable Easy to extend Sending notifications
  36. Demo

  37. Your Laravel app may break Server may be down Install

    the package in a Laravel app on a separate server Monitor the backups of all your apps from there Monitoring best practices
  38. Monitoring best practices APPS BACKUPS MONITOR

  39. Install a Laravel app on the same server Point the

    configuration the the database/directories you which to backup Profit! Backing up a non Laravel app
  40. Backup to multiple filesystems Get notified when something goes wrong

    Monitor the health of your backups Easy installation Free Benefits
  41. Backup to multiple filesystems Get notified when something goes wrong

    Monitor the health of your backups Easy installation Free Benefits
  42. Drawbacks Can consume quite a bit a of disk space

    while backing up Application has credentials to access the backups No restore options
  43. https://docs.spatie.be/laravel-backup

  44. Questions?

  45. Thank you! https://joind.in/talk/cc523 https://speakerdeck.com/freekmurze/backing-up-with-laravel https://murze.be https://spatie.be/opensource