Deprecated: Creation of dynamic property wpdb::$categories is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/wp-db.php on line 760

Deprecated: Creation of dynamic property wpdb::$post2cat is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/wp-db.php on line 760

Deprecated: Creation of dynamic property wpdb::$link2cat is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/wp-db.php on line 760

Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /home3/achieve/public_html/knowledgebase/wp-includes/comment-template.php on line 1747

Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /home3/achieve/public_html/knowledgebase/wp-content/plugins/contact-form-7/includes/mail.php on line 109

Warning: The magic method GADWP_Manager::__wakeup() must have public visibility in /home3/achieve/public_html/knowledgebase/wp-content/plugins/google-analytics-dashboard-for-wp/gadwp.php on line 76

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home3/achieve/public_html/knowledgebase/wp-content/plugins/google-analytics-dashboard-for-wp/tools/gapi.php on line 539

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home3/achieve/public_html/knowledgebase/wp-content/plugins/google-analytics-dashboard-for-wp/tools/gapi.php on line 569

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home3/achieve/public_html/knowledgebase/wp-content/plugins/google-analytics-dashboard-for-wp/tools/gapi.php on line 601

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home3/achieve/public_html/knowledgebase/wp-content/plugins/google-analytics-dashboard-for-wp/tools/gapi.php on line 635

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home3/achieve/public_html/knowledgebase/wp-content/plugins/google-analytics-dashboard-for-wp/tools/gapi.php on line 670

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home3/achieve/public_html/knowledgebase/wp-content/plugins/google-analytics-dashboard-for-wp/tools/gapi.php on line 729

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home3/achieve/public_html/knowledgebase/wp-content/plugins/google-analytics-dashboard-for-wp/tools/gapi.php on line 769

Deprecated: Creation of dynamic property POMO_FileReader::$is_overloaded is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/streams.php on line 26

Deprecated: Creation of dynamic property POMO_FileReader::$_pos is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/streams.php on line 29

Deprecated: Creation of dynamic property POMO_FileReader::$_f is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/streams.php on line 160

Deprecated: Creation of dynamic property MO::$_gettext_select_plural_form is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/translations.php on line 292

Deprecated: Creation of dynamic property POMO_FileReader::$is_overloaded is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/streams.php on line 26

Deprecated: Creation of dynamic property POMO_FileReader::$_pos is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/streams.php on line 29

Deprecated: Creation of dynamic property POMO_FileReader::$_f is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/streams.php on line 160

Deprecated: Creation of dynamic property MO::$_gettext_select_plural_form is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/translations.php on line 292

Deprecated: Creation of dynamic property WP_Block_Type::$skip_inner_blocks is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/class-wp-block-type.php on line 391

Deprecated: Creation of dynamic property WP_Block_Type::$skip_inner_blocks is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/class-wp-block-type.php on line 391

Deprecated: Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/achieve/public_html/knowledgebase/wp-includes/Requests/Cookie/Jar.php on line 63

Deprecated: Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/achieve/public_html/knowledgebase/wp-includes/Requests/Cookie/Jar.php on line 73

Deprecated: Return type of Requests_Cookie_Jar::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/achieve/public_html/knowledgebase/wp-includes/Requests/Cookie/Jar.php on line 89

Deprecated: Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/achieve/public_html/knowledgebase/wp-includes/Requests/Cookie/Jar.php on line 102

Deprecated: Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/achieve/public_html/knowledgebase/wp-includes/Requests/Cookie/Jar.php on line 111

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/achieve/public_html/knowledgebase/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 40

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/achieve/public_html/knowledgebase/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 51

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/achieve/public_html/knowledgebase/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 68

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/achieve/public_html/knowledgebase/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 82

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/achieve/public_html/knowledgebase/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 91

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/class-wp-term-query.php on line 1118

Warning: Cannot modify header information - headers already sent by (output started at /home3/achieve/public_html/knowledgebase/wp-includes/wp-db.php:760) in /home3/achieve/public_html/knowledgebase/wp-includes/feed-rss2.php on line 8
Helpers – Knowledge http://knowledge.achieveee.com Wed, 03 Apr 2019 14:59:24 +0000 en-US hourly 1 https://wordpress.org/?v=6.0.7 http://knowledge.achieveee.com/wp-content/uploads/2016/05/cropped-favicon-32x32.png Helpers – Knowledge http://knowledge.achieveee.com 32 32 Scheduling MySQL backups with Laravel http://knowledge.achieveee.com/knowledge_base/scheduling-mysql-backups-with-laravel/ http://knowledge.achieveee.com/knowledge_base/scheduling-mysql-backups-with-laravel/#respond Wed, 03 Apr 2019 14:50:15 +0000 http://knowledge.achieveee.com/?post_type=knowledge_base&p=2591 To manually dump the database you can run the following one-liner code

mysqldump -u[user] -p[pass] [db] > [file_path]

But what if you want to automate the process? Listing down the steps one by one:

    1. Setup cron entry to your server
      * * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
    2. Create a command BackupDatabase by running the following code:
      php artisan make:command BackupDatabase
    3. Navigate to app/Console/Commands/BackupDatabase.php and replace the code the following:
      <?php
      
      namespace App\Console\Commands;
      
      use Illuminate\Console\Command;
      use Symfony\Component\Process\Process;
      use Symfony\Component\Process\Exception\ProcessFailedException;
      
      class BackupDatabase extends Command
      {
          protected $signature = 'db:backup';
      
          protected $description = 'Backup the database';
      
          protected $process;
      
          public function __construct()
          {
              parent::__construct();
      
              $this->process = new Process(sprintf(
                  'mysqldump -u%s -p%s %s > %s',
                  config('database.connections.mysql.username'),
                  config('database.connections.mysql.password'),
                  config('database.connections.mysql.database'),
                  storage_path('app/backups/backup-' . time() . '.sql')
              ));
          }
      
          public function handle()
          {
              try {
                  $this->process->mustRun();
      
                  $this->info('The backup has been proceed successfully.');
              } catch (ProcessFailedException $exception) {
                  $this->error('The backup process has been failed.');
              }
          }
      }
    4. Schedule the backup task, navigate to app/Console/Kernel.php and append the following line of code inside schedule method to run database backups every Saturday at 11PM. You can set the frequency as per your requirements
      $schedule->command('db:backup')->saturdays()->at('23:00');
    5. Create backups directory inside storage/app directory and place a .gitignore file inside backups directory with the following code
      *
      !.gitignore

That’s it you’ve now enabled weekly automated database backups
For more information and credits: https://pineco.de/scheduling-mysql-backups-with-laravel/

]]>
http://knowledge.achieveee.com/knowledge_base/scheduling-mysql-backups-with-laravel/feed/ 0