Created
January 16, 2018 13:38
-
-
Save edirpedro/6e5e0cab983147b0f7e58c955616f2cb to your computer and use it in GitHub Desktop.
Automate uploading backups to S3 with AWS CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Automate uploading backups to S3 with AWS CLI | |
# Go to AWS Console and create an user with access to your bucket and a single permission to the action "PutObject" | |
# Sample policy: {"Version": "2018-01-15","Statement": [{"Effect": "Allow","Action": "s3:PutObject","Resource": ["arn:aws:s3:::BUCKETNAME/*","arn:aws:s3:::BUCKETNAME"]}]} | |
# Login to SSH as root | |
# sudo apt-get install python-pip | |
# sudo pip install awscli | |
# aws configure (defaults region "us-east-1" and output "text") | |
# crontab -e (add a line "0 6 * * * sudo /path/to/s3.sh") | |
# Change path and bucket below! | |
for file in $(find /path/to/backup/*.tar -mtime -1); do | |
filename=$(basename $file) | |
aws s3 cp $file s3://bucket/$filename | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment