I would approach the task a bit differently. Use the venerable rsync command which is specifically designed for this scenario.
- Install Homebrew from https://brew.sh
- Then brew install rsync to install the latest version which is much newer than what Apple ships in macOS
- Verify the correct rsync by issuing the commands "which rsync" and "rsync --version" it should not be version 2.6.9.
- Learn about rsync (google it -- Linux rsync is the same) and try a mirror command to work from source to destination. But if that doesn't do what you want you can just copy the files to the backup location. See the options mentioned below that are specific to macOS ACL's (Access Control List preservation)
- When you've got a command with options that works you can create a Launchd plist to run every few minutes so it will constantly be mirroring the content from folder A to folder B. Mirror will remove files that were deleted from folder A in folder B. Otherwise you can use the options below which is merely copying the files.
% rsync -rlAXtgoD --fake-super /source/ /destination
↑ super important slash at end of source path
Summary of options:
# -r recursive; recurse into directories
# -l copy symlinks as symlinks
# --acls, -A preserve ACLs (implies --perms, -p)
# --xattrs, -X preserve extended attributes
# -t preserve modification times
# -g preserve group
# -o preserve owner
# -D preserve devices and special files
# -v increased verbosity; may be repeated
# -i itemize changes
# --fake-super store/recover privileged attrs using xattrs (for ACLs & XATTRs)
# --dry-run perform a trial run with no changes made
This document describes how to create a launchd XML plist to run a command every few minutes.
https://www.maketecheasier.com/use-launchd-run-scripts-on-schedule-macos/