Saturday, 2 January 2016

Backing up the Plesk log files to Amazon AWS s3 bucket using s3cmd tool

Amazon S3 is one of the most reliable backup location. So we had a requirement to backup the website logs to S3 bucket for data retention purpose. We have achieved this using s3cmd command line tool in Centos 6.3 server.


In a Plesk server, the log files are located at /var/www/vhosts/sitename/statistics/logs folder. S o we need to recursively upload these folders to s3 bucket. I have created an S3 bucket called "backup.server"

First step is to install s3cmd tool in CentOS 6.3 Plesk server.


To install  S3cmd in centos :

cd /etc/yum.repos.d/

wget http://s3tools.org/repo/RHEL_6/s3tools.repo

yum install s3cmd

Now to configure s3cmd using: -

s3cmd --configure 

Now go to the folder /var/www/vhosts/

cd /var/www/vhosts/

Create a screen there using 'screen' command :

Now type the below command in screen and let it run

for i in `ls`; do s3cmd -r put  $i/statistics/logs s3://backup.server/logs/pleskserver/$i/ ;done

This will recursively backup all the log files in all vhosts to s3bucket called "backup.server" under https://s3.amazonaws.com/backup.server/logs/pleskserver/mydomain.com/logs/

If you want to do a regular backup, you can add this command to cron job.

No comments:

Post a Comment