How to exclude files and directories

BackWPup let you exclude some files and folders in the back up process through is settings page. We recently implemented new hooks to let you manage and extends these setting via code. Here follows a brief tutorial on how to achieve that result.

Jobs files settings page

If you create a new Job going to BackWPup->New Job and then select the Files tab, you land into the Folders to backup settings section.

Excluding files and folders settings page
Excluding files and folders settings page

From here you can exclude some folders and some file of your installations from the back up process.

But now you can also extend some of that options through new filter hooks.

Besides you can alternatively set an option using a filter, instead of managing it in the back end.

Let’s have a look to every hooks.

Add folders to exclude in Backup content folder list

The hook backwpup_content_exclude_dirs let you add directories in the list of the ones that you wish to exclude from the back up process in your wp-content WordPress directory.

Suppose you have the folders named as just-a-folder and another-folder in your WordPress wp-content directory. If you want to add these folders in the in Backup content folder exclude list, you can implement the following filter:

add_filter(
      'backwpup_content_exclude_dirs',
      function ($directories) {
          array_push(
                      $directories,
                      'just-a-folder',
                      'another-folder'
                    );
          return $directories;
      }
);

Here below you can see how the filter affects the Backup content folder exclude list, the new folder are added as an option.

Folders added in the in Backup content folder exclude list
Folders added in the in Backup content folder exclude list

Add folders to exclude in other settings lists

Similarly as described in the previous section, if you need to add new directories to be excluded from the back up in your job settings lists, you can create your own filter.  You can achieve that using the hooks listed here below:

backwpup_plugins_exclude_dirs

This hook let you extend the Backup plugins list. It lets you add the folders you want to exclude in your WordPress wp-content/plugins directory.

backwpup_themes_exclude_dirs

This hook let you extend the Backup themes list. It lets you add the folders you want to exclude in your WordPress wp-content/themes directory

backwpup_upload_exclude_dirs

This hook let you extend the Backup upload folder list. It lets you add the folders you want to exclude in your WordPress wp-content/upload directory

Exclude files and folders

If you need to exclude any folder or file from the WordPress root directory in your server you can use the Exclude files/folders from backup text area in the GUI: just add the folders and the file extensions you want to exclude separated by comma.

But if you want to achieve the same result using a filter this is again possible via the hook backwpup_file_exclude .

Here below we provide an implementation example that let you add two file extensions (.pdf and .epub) in the list of files you want to exclude from the back up.

add_filter(
    'backwpup_file_exclude',
    function ($fileExtensions) {
        return $fileExtensions . ',.pdf,.epub';
    }
);

Then, if we head to our back end settings, we can see how these two extensions have been properly set in the Exclude files/folders from backup text area, as shown below.

Exclude folders and/or file extensions
Exclude folders and/or file extensions