#!/bin/bash input="" prefix="" bucket="" while [[ "$#" -gt 0 ]]; do case $1 in -p | --prefix) shift prefix="/$1" ;; -b | --bucket) shift bucket="$1" ;; *) input="$1" ;; esac shift done if [ -z "$bucket" ]; then echo "Bucket name is required" exit 1 fi if [ -d "$input" ]; then cd $input if [ ! -d .git ]; then echo "Specified directory is not a git repository" exit 1 fi diff=$(git diff --name-only) files=($diff) pwd="$(pwd)" echo "Backing up modified tracked files in '$pwd' to S3 bucket '$bucket'..." for file in "${files[@]}"; do path="$pwd/$file" aws s3 cp "$path" "s3://$bucket$prefix$path" done elif [ -f "$input" ]; then pwd="$(pwd)" path="$pwd/$input" echo "Backing up individual file to S3 bucket '$bucket'..." aws s3 cp "$path" "s3://$bucket$prefix$path" else echo "No file or directory '$input'" exit 1 fi