- 1 year ago
How to keep AWS cli sync from copying files that are listed in the --exclude switch
When using the AWS Command Line Interface (CLI) aws s3 sync
command, you can exclude specific files or directories from being copied by providing the --exclude
option. However, if you want to prevent files listed in the --exclude
option from being copied, you'll need to modify your approach slightly.
One way to achieve this is by using the --exclude
option in combination with the --exclude-pattern
option. The --exclude-pattern
option allows you to specify a pattern that matches the files or directories you want to exclude.
Here's an example command that demonstrates how to exclude files listed in the --exclude
option from being copied:
bashaws s3 sync <source> <destination> --exclude "file1.txt" --exclude "dir1/*" --exclude-pattern "file1.txt" --exclude-pattern "dir1/*"
In the above command:
<source>
refers to the source directory or S3 bucket you want to sync from.<destination>
refers to the destination directory or S3 bucket you want to sync to.--exclude "file1.txt"
excludes a specific file named "file1.txt" from being copied.--exclude "dir1/*"
excludes all files and subdirectories within "dir1" from being copied.--exclude-pattern "file1.txt"
prevents files matching the pattern "file1.txt" from being copied.--exclude-pattern "dir1/*"
prevents files and subdirectories matching the pattern "dir1/*" from being copied.
By providing both the --exclude
and --exclude-pattern
options with the same values, you can effectively prevent the listed files from being copied during the synchronization process.
Note that you need to adjust the command according to your specific use case, specifying the appropriate source and destination paths, as well as the files or directories you want to exclude.
Make sure you test the command with sample data to ensure it behaves as expected and excludes the desired files while performing the sync operation.