Auto webserver and database backup with GPG encryption to Amazon S3

In this tutorial I will show you step-by-step  instructions how to make cheap and secure encrypted backups of you webserver (or any other dir)  files on you linux  server using Amazon Storage Service

Create Bucket and User at Amazon AWS

Some links that we will need

Firstly create an user at Amazon IAM managment console. Don’t forget to set permision – AmazonS3FullAccess. Copy your access and secret keys. You will need it later

Now create a bucket for a backups at Amazon S3. For testing you can leave all settings by default.

Install AWS CLI tools on your server machine

Now you can install Amazon AWS command line interface. For that you will need Python and Pip. If you don’t have it, you can found  a very nice tutorial here .

You may need to export path where aws was installed .

Add the executable path to your PATH variable: ~/.local/bin

Configurate access to Amazon S3. Use your access keys from IAM. Also you will need Amazon region string. You can find it here

Now you can test if you can copy any files to your bucket

Creating Database and Webserver backup with encryption

Create a backup shell script file. If you get an error, try to run with sudo

Content of backup.sh

Set the excecution permision on backup.sh

Create log file (feel free to change the path) and open  Crontab window

Add the following text to the end of crontab file (there is Crontab Generator, where you can easily set your execution schedule).

Just in case , test you script

Sure later you may need to decrypt it

Leave a Reply

Your email address will not be published. Required fields are marked *