Skip to content

Instantly share code, notes, and snippets.

@StudioLE
Created January 21, 2017 22:08
Show Gist options
  • Select an option

  • Save StudioLE/af96acaf589c3d037e9c04baa9304773 to your computer and use it in GitHub Desktop.

Select an option

Save StudioLE/af96acaf589c3d037e9c04baa9304773 to your computer and use it in GitHub Desktop.
Sync directory to S3
*/5 * * * * ~/sync.sh >> ~/sync.log 2>&1
#!/bin/bash
echo "----"
# Timestamp
date
# Create lock file
(
# Exit with failure if already in use
flock -n -e 9 || { echo "Exiting: Sync in progress" && exit 1; }
# Sync directory to S3
# Use trickle to limit to 120 kB/s
/usr/bin/trickle -s -u 120 /usr/local/bin/aws s3 sync /PATH/TO/DIRECTORY s3://BUCKET/PATH
) 9>/tmp/sync.lockfile
# Timestamp
date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment