3 Easy Steps To Perform Automated Backup In Drupal 9

3 Easy Steps To Perform Automated Backup In Drupal 9

Easy Steps To Perform Automated Backup In Drupal

There are different ways for Drupal writers to back up their Drupal websites. This article is about two of my favorite ways to back up a Drupal 8 or Drupal 9 website. One with the help of the Drupal plugin Backup and migrate. And the other way is to use CLI with Cron jobs. 

No matter who or what caused it, losing data can be terrible and painful. The good news is that it can be stopped if you back up your site regularly. There are times when backups are done every day and times when they are done less often. How often it happens depends on things like how big your Drupal site is or how often you change it. With the Backup and migrate Drupal module and the command line interface (CLI), Drupal 8 and 9 make it easier to back up and recover your website.

TABLE OF CONTENT

Using the Drupal 8 and 9 Backup and Migrate Module

Both databases and files can be backed up by the backup and migrate tool. It can also make a backup of the Drupal program folder as a whole. The module also has a security feature that needs you to download a separate library called the Defuse PHP encryption library.

composer require defuse/php-encryption

How to use it:

  • Install the tool for backing up and moving data.
  • Make a private directory and give it the same rights as the files folder, which means it can be written to.
  • In the settings.php file, set the path to the private location so that the module can use it to store backups.

Backup and Migrate

Module for Backup and Migration

Backup and Migrate Module User Interface

After installing the module, go to Administration > Configuration > Development > Backup and Migrate. There are 5 tabs:

Backup is where you can back up quickly. When you click on Backup now, it will show up in the Saved Backups tab

Restore: This is where you can bring back files from before.

Saved saves is where you can see a list of all the saves you’ve made so far.

Schedules— where you can set up when your saves will happen

Settings –  has choices and settings for this module as a whole.

Schedules:

One of the most important parts of the section is the schedules. The tool gives you an automatic scheduler that you can use to plan when your backup will happen. Every time cron starts, this is done automatically. You can add as many schedules as you want to back up the database, public or secret file directories, or the whole site.

Schedules

 

Setting up the schedule

Here is where the plans can be added to or changed. You can call the schedule something. You can pick whether or not to use the calendar. You can back up the database, public or private files, folders, or the whole site. Or, you can add your own under “Settings.” If you are backing up both the database and the files, you can set each type of backup to go to a different place. This means that you can store your database backups in a different place than your file backups, and so on. On the Settings tab, the module also has settings that let you add more locations of your choice. With the Frequency choice, you can tell cron how often you want a backup to happen. There are choices for hours, minutes, days, and weeks. With the Numbers to keep setting, we can choose how many backups we want to keep. Once it hits the limit you set, it deletes the older backups automatically. This solves memory and storage problems. 

Setting up the schedule

Setting up schedules

Adding a source of backup

Adding a source of backup

Is there anything you can’t do?

I’m afraid so. From my own experience, I know that I do get Time-out problems when the size of the database grows. This is a problem because we can’t increase the largest amount of time the database can run on some servers. The other problem I’ve had is that I can’t remember things. It may run out of memory based on how the server is set up, how big the database is, or how big the backup is. We can use the CLI way when we run into these kinds of problems.

How to Back Up with CLI 

In the command-line input method, there are two ways to make backups:

  • Using Drush and the Crontab together
  • Depending on what we need to back up, we use both Native scripts and Crontab.

 Drush and Crontab are used

Scenario: Setting up a database backup to happen every morning at 3 a.m. –

How to Read:

0 3 * * * <path-to-drush> -r <path-to-drupal-root> sql:dump –result-file=<filename>.sql –gzip

For example:

0 3 * * * /var/www/html/drupal_demo/vendor/drush/drush/drush -r /var/www/html/drupal_demo sql:dump –result-file=/var/www/html/drupal_demo/db-dump-`date +%d%m%Y%H%M%S`.sql –gzip

Native instructions and Crontab are used.

Scenario: Setting up a database backup to happen every morning at 3 a.m. is the same scenario.

How to Read:

0 3 * * * mysqldump -u <mysql_username> -p <mysql_database_name> | gzip -c > <path-to-filename>.sql.gz

For example:

0 3 * * * mysqldump -u drupal -p drupal_demo | gzip -c > 

/var/www/html/drupal_demo/db-dump-`date +%d%m%Y%H%M%S`.sql.gz

Scenario: Setting up a Files backup to happen every morning at 5 a.m. –

How to Read:

0 5 * * * tar -czvf <path-to-backup-filename>.tgz <source>

For example:

0 5 * * * tar -czvf /home/ubuntu/backups/drupal_demo-files-`date +%d%m%Y%H%M%S`.tgz 

/var/www/html/drupal_demo/web/sites/default/files/

Backups are important for more than just moving your website. The best way to protect yourself from losing info is to make backups regularly. And it doesn’t have to be a tedious job because Drupal 8 and 9 have modules that can help handle backups. The two best ways to handle your backups are the Backup and Migrate module and the CLI method we talked about here. Want to know more about how we can use these great Drupal modules and tools in your next project? Talk to one of our pros on Drupal today.

Conclusion

At the end of this post, we hope you were able to learn about the Drupal plugins that your ecommerce store must have. But if you are looking for a company that builds websites with Drupal, you should check out Appic Softwares

We have an experienced team of Drupal developers who can help you manage and keep your Drupal website.

You can even hire Drupal writers from us who will take care of your production. So, why are you still waiting?

Contact us now!

Get Free Consultation Now!


    Our Engagment Model

    •   Hourly Hiring

    •   Fixed Hiring

    •   Dedicated Team

    Contact Us

    Consult us today to develop your application.

      Get in touch with us


      Skype Whatsapp Gmail Phone