Last active
September 22, 2022 14:22
-
-
Save snghnishant/24a1281893f82a5237120e61d0e134de to your computer and use it in GitHub Desktop.
Bash script to upload to S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BUCKET_NAME="bucket_name_here" # "stratzy-logs" | |
FILE_UPLOAD_LOCATION="directory_name_inside_bucket" # "system" | |
FILE_TO_UPLOAD_LOCATION= "local_directory" #"/home/ec2-user/.pm2/logs/" | |
# Using loop | |
# for FILE in $FILE_TO_UPLOAD_LOCATION | |
# do | |
# filename=$(basename $FILE) | |
# echo "Started uploading $filename" | |
# aws s3 cp $FILE s3://$BUCKET_NAME/$FILE_UPLOAD_LOCATION | |
# echo "Finished uploading $filename" | |
# done | |
# Recursive mode | |
echo "Started uploading" | |
aws s3 cp $FILE_TO_UPLOAD_LOCATION s3://$BUCKET_NAME/$FILE_UPLOAD_LOCATION --recursive --include "*.log" | |
# use --exclude flag to exclude certain filetype | |
echo "Finished uploading on $BUCKET_NAME/$FILE_UPLOAD_LOCATION" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment