Skip to content

Instantly share code, notes, and snippets.

@kitwalker12
Created April 27, 2016 17:11
Show Gist options
  • Save kitwalker12/209b0b611f1a11c5056497aeb1e44528 to your computer and use it in GitHub Desktop.
Save kitwalker12/209b0b611f1a11c5056497aeb1e44528 to your computer and use it in GitHub Desktop.
S3 Backup locally script (use absolute paths for files)
0 21 * * * s3backup.sh >> crontab.out 2> crontab.err &
0 5 * * * s3stopbackup.sh >> crontab.out 2> crontab.err &
#!/bin/sh
export PATH=/opt/bin:/opt/sbin:/usr/bin/:/usr/local/bin:$PATH
if (ps -A | grep aws | grep -v grep)
then
echo "s3backup.sh: `date +%Y%m%d-%H%M` - Backup already in progress" >> aws-sync.log
exit
fi
echo "s3backup.sh: `date +%Y%m%d-%H%M` - Backup started" >> aws-sync.log
aws s3 sync s3://<my-bucket> <local-backup-path> >> aws-sync.log
echo "s3backup.sh: `date +%Y%m%d-%H%M` - Backup completed" >> aws-sync.log
#!/bin/sh
if (ps -A | grep aws | grep -v grep)
then
kill `ps -A | grep s3backup.sh | grep -v grep | awk '{print $1}'`
echo "s3stopbackup.sh: `date +%Y%m%d-%H%M` - s3backup.sh killed" >> aws-sync.log
kill `ps -A | grep aws | grep -v grep | awk '{print $1}'`
echo "s3stopbackup.sh: `date +%Y%m%d-%H%M` - aws killed" >> aws-sync.log
else
echo "s3stopbackup.sh: `date +%Y%m%d-%H%M` - aws not running" >> aws-sync.log
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment