Skip to content

Instantly share code, notes, and snippets.

@alismx
Last active April 8, 2023 20:08
Show Gist options
  • Save alismx/7a42ab3b5203a9eca579f0a80a9dc63b to your computer and use it in GitHub Desktop.
Save alismx/7a42ab3b5203a9eca579f0a80a9dc63b to your computer and use it in GitHub Desktop.
This is a script to sync to s3 compatible tools (AWS S3, Digital Ocean Spaces)
# Add these variables to your environment or define them in the script
# export BUCKET_URL=s3://your-bucket-name/path-to-files/
# export LOCAL_DIR=/path/to/local/dir/
#!/bin/bash
function file_sync() {
local operation=$1
local source=$2
local destination=$3
echo "$(date): Starting $operation..."
if s3cmd sync "$source" "$destination"; then
echo "$(date): File $operation complete."
else
echo "$(date): Error occurred while $operation files."
exit 1
fi
}
case "$1" in
upload)
file_sync "upload" "$LOCAL_DIR" "$BUCKET_URL"
;;
download)
file_sync "download" "$BUCKET_URL" "$LOCAL_DIR"
;;
*)
echo "Invalid argument. Please specify either 'upload' or 'download'."
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment