Skip to content

Instantly share code, notes, and snippets.

@dantman
Created March 27, 2025 17:53
Show Gist options
  • Save dantman/fe7fcb490771741afb80f8f1578e701e to your computer and use it in GitHub Desktop.
Save dantman/fe7fcb490771741afb80f8f1578e701e to your computer and use it in GitHub Desktop.
s3upload script for uploading backups from a really old server
#!/bin/bash
# Configuration
# ACCESS_KEY="YOUR_ACCESS_KEY"
# SECRET_KEY="YOUR_SECRET_KEY"
# BUCKET="your-bucket-name"
# REGION="your-region"
# SUBPATH="your-subpath"
# Function to upload a file
upload_file() {
FILE_PATH="$1"
FILE_NAME=$(basename "$FILE_PATH")
DATE=$(date -u +"%Y%m%dT%H%M%SZ")
# Create signature
STRING_TO_SIGN="PUT\n\n${CONTENT_TYPE}\n${DATE}\n/${BUCKET}/${SUBPATH}/${FILE_NAME}"
SIGNATURE=$(echo -en ${STRING_TO_SIGN} | openssl sha1 -hmac ${SECRET_KEY} -binary | base64)
# Upload
curl -X PUT -T "${FILE_PATH}" \
-H "Date: ${DATE}" \
-H "Authorization: AWS ${ACCESS_KEY}:${SIGNATURE}" \
"https://${BUCKET}.s3.${REGION}.amazonaws.com/${SUBPATH}/${FILE_NAME}"
}
# Usage
if [ -z "$1" ]; then
echo "Usage: $0 /path/to/file"
exit 1
fi
upload_file "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment