You have to think about it the opposite way. You do not want to back up just one folder. You want to have a files-only backup where all files and folders are excluded except a subdirectory of the images folder.
The backup profile needs to have the backup type "Site files only".
Now, we need four things:
- Exclude all files in the site's root
- Exclude all top folders except
images
.
- Exclude all files directly under
images
.
- Exclude all folders under
images
except folder_to_keep
.
The simple and stupid* way to do that is use the Files and Directories Exclusion page. However, if you add any files in the site's root, or any new subdirectories under images
you'll have to update the backup profile and we don't want that. So, let's do this properly, with RegEx Files And Directories Exclusion. Finally, 13 years later, someone asks me how to use this feature for the very reason I implemented it in the first place!
We need three regex filters:
- Exclude file,
!#.*/.*#
- Exclude directory,
!#^images(/folder_to_keep(/.*)?)?$#
- Exclude file,
#^images/[^/]*$#
The first one excludes all files in the site's root.
The second one excludes all folders except images
itself (we can't exclude, as we need to scan it to find the images/folder_to_keep directory during the backup), the images/folder_to_keep
directory, and its subdirectories.
The third one excludes all files directory under the images
folder.
So, there you have it! You are now only backing up the contents of images/folder_to_keep
.
* No disrespect here. "Simple and stupid" refers to the KISS (Keep It Simple and Stupid) principle in computing, meaning that low-effort solutions are valid solutions as long as they work.
Nicholas K. Dionysopoulos
Lead Developer and Director
🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!