Skip to content

Instantly share code, notes, and snippets.

@snghnishant
Last active September 22, 2022 14:22
Show Gist options
  • Save snghnishant/24a1281893f82a5237120e61d0e134de to your computer and use it in GitHub Desktop.
Save snghnishant/24a1281893f82a5237120e61d0e134de to your computer and use it in GitHub Desktop.
Bash script to upload to S3
#!/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