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.
Table of Contents
Exclude Settings
In the BackWPUp>Settings page, you can click ‘select files’ under ‘Files’ to manage this.
Here, you can choose which files and directories from your installations should not be backed up.
However, new filter hooks now allow you to expand some of those possibilities as well.
Additionally, rather than handling it at the back end, you can use a filter to set an option.
Let us examine each hook in turn.
Add folders to exclude in Backup content folder list
The hook backwpup_content_exclude_dirs lets you add directories in the list of the ones that you wish to exclude from the backup process in your wp-content WordPress directory.
Suppose you have the folders named just-a-folder and another-folder in your WordPress wp-content directory. If you want to add these folders to the 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; } );
You will see these folder option to exclude in the settings.
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 backup, you can create your own filter. You can achieve that using the hooks listed here below:
backwpup_plugins_exclude_dirs
This hook lets 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 lets 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 lets 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 on 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 settings, we can see how these two extensions have been properly set in the Exclude files/folders/extensions from backup, as shown below.