How can I exclude particular files/directories from the backup?

UpdraftPlus provides a number of ways to exclude files or directories from the backup.

These are:

1. List them directly in the “exclude” settingsExcluding via options

Any files or directories that you directly list will be excluded. You can use a wildcard at the beginning or end, in order to exclude any files or directories at the top level matching that pattern. (The default setting uses this to exclude backups created by a number of other plugins). The above screenshot excludes any files or directories in “uploads” whose names begin with “backup”, and also excludes the entire directory 2015/05 (i.e. wp-content/uploads/2015/05).

You can add as many as you like; to do so, separate them with commas. (But not with spaces – a comma only). Also, make sure that you’re adding them to the correct setting.

2. Create a file called .donotbackup in a directory

If you create a file called “.donotbackup” (without the quotes) in any directory, then that directory (and its sub-directories) will be excluded from the backup.

3. Exclude files with particular extensions

You can exclude files with chosen extensions by either:

a) Adding them to the exclusion setting (see 1, above), by identifying them with “ext:”; e.g. ext:mp3,ext:mp4.

Excluding specific file extensions

b) Or, you can add a line in your wp-config.php to define the constant UPDRAFTPLUS_EXCLUDE_EXTENSIONS; for example (again, extensions are separated by commas, only):

define('UPDRAFTPLUS_EXCLUDE_EXTENSIONS', 'mp3,mp4');

4. Exclude files with particular prefixes

This is the counter-part of excluding files based upon the suffix in their filename; you can also do it via prefix (i.e. the characters that begin the filename). To do this, add them to the exclusion setting (see 1, above), by identifying them with “prefix:”; e.g. prefix:abc will exclude any files whose names begin with abc.

Excluding files via prefix

5. Exclude directories using a WordPress filter

You can write a small code snippet (e.g. as an mu-plugin, or in your child theme’s functions.php file) to exclude any directory you desire from the backup, using a WordPress filter. You can make the code as simple or complicated as you like. The filter to use is updraftplus_skip_directory, which returns a boolean (true to skip, or false (the default) to not skip), and whose other parameter is the full directory path. Here is an example of a code snippet to skip all .git directories:
add_filter('updraftplus_exclude_directory', 'my_updraftplus_exclude_directory', 10, 2);
function my_updraftplus_exclude_directory($filter, $dir) {
return (basename($dir) == '.git') ? true : $filter;
}

6. Exclude files using a WordPress filter

In the same way as described above for directories, there is a filter updraftplus_exclude_file which you can use to prevent the backup of particular files. The below example will prevent the backup of any files called bertie.jpg :
add_filter('updraftplus_exclude_file', 'my_updraftplus_exclude_file', 10, 2);
function my_updraftplus_exclude_file($filter, $file) {
return (basename($file) == 'bertie.jpg') ? true : $filter;
}

Posted in: Advanced usage, Configuration

twitterlinkedinFacebook