понедельник, 11 августа 2014 г.

Save files on AWS S3 into console

Productivity Sauce

May 20, 2010 GMT
Dmitri Popov
Amazon S3 provides unlimited storage at low prices, which makes it an ideal solution for storing backups. But to make use of it, you need a piece of software that can actually interact with Amazon S3: create buckets, list the contents of a bucket, upload and download files, etc. And aws, a simple command-line utility written in Perl, is the perfect tool for the job. You might wonder why not use a GUI-based application like Jungle Disk? For two simple reasons: as a CLI-based tool, aws is light on resources and it can be easily scripted.
Before you proceed, you should install the curl utility. On Ubuntu, you can do this using the sudo apt-get install curl command. Next, grab the latest version of the aws script:
curl timkay.com/aws/aws -o aws
Make it then executable and copy it to the /usr/bin directory:
chmod +x aws
sudo cp ~/aws /usr/bin/
Create then an .awssecret file and open it in a text editor like nano:
nano .awssecret
Enter your Amazon AWS credentials (the Access Key ID and the Secret Access Key) as follows:
1B5JYHPQCXW13GWKHAG2
2GAHKWG3+1wxcqyhpj5b1Ggqc0TIxj21DKkidjfz
Save the file and change its permissions:
chmod 600 .awssecret
aws is now ready to go. To create a bucket for your backup use the aws mkdir command (replacingBUCKET with the actual name):
aws mkdir BUCKET
Next, create a tarball of the directory you want to back up using the tar tool:
tar -pvczf tmp/dir.tar.gz /path/to/dir
Finally, upload the created archive to the created bucket:
aws put BUCKET/dir.tar.gz /path/to/dir.tar.gz
The best part is that you don't have to do this manually every time you want to back up a certain directory. Here is a sample script that backs up photos stored on the local hard disk:
#!/bin/bash
cd /home/user/
tar -pvczf Photos.tar.gz Photos
aws put BUCKET/Photos.tar.gz Photos.tar.gz

Tweak the script to your liking, schedule it using cron, and your perfect Amazon S3-based backup solution is ready to go.

Взято из http://www.linux-magazine.com/Online/Blogs/Productivity-Sauce/Perfect-Backup-Solution-with-Amazon-S3-and-aws