Skip to content

Instantly share code, notes, and snippets.

@asraful
Created September 2, 2020 10:22
Show Gist options
  • Select an option

  • Save asraful/0c930d8e942d3c9533d51e8c5538e4ca to your computer and use it in GitHub Desktop.

Select an option

Save asraful/0c930d8e942d3c9533d51e8c5538e4ca to your computer and use it in GitHub Desktop.
Write a cron job used in EC2 to backup data from ec2 to certain s3 bucket
#!/bin/sh
WK_DIRECTORY=$1
WK_BUCKET=$2
JOB_INTERVAL=$3
pip install --user awscli --upgrade
command="/usr/local/bin/aws s3 sync $WK_DIRECTORY s3://$WK_BUCKET"
echo $command
job="*/$JOB_INTERVAL * * * * $command"
echo "$job"
crontab -l | { cat; echo "$job"; } | crontab -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment