How to Upload Backup to Amazon S3

sohaib

Verified User
Joined
Apr 27, 2005
Messages
189
Location
Shared & Dedicated Hosting
Hello !!!!!

This guide is for CENTOS 6.x x32 or x64

yum install s3cmd -y - If you can't install s3cmd then please follow the instructions

Code:
cd /etc/yum.repos.d
Code:
touch s3cmd.repo
Code:
nano s3cmd.repo

AND COPY THE CODE BELOW -

Code:
# 
# Save this file to /etc/yum.repos.d on your system
# and run "yum install s3cmd"
# 
[s3tools]
name=Tools for managing Amazon S3 - Simple Storage Service (RHEL_6)
type=rpm-md
baseurl=http://s3tools.org/repo/RHEL_6/
gpgcheck=1
gpgkey=http://s3tools.org/repo/RHEL_6/repodata/repomd.xml.key
enabled=1

Try Above YUM Command again - This time it will install S3CMD, Once installation is completed try running the following command - It will configure your S3CMD using your AMAZON KEY AND Access ID.

Code:
s3cmd --configure

Once above is done - Create another file for example in /home/admin/user_backups or where ever you like

Code:
nano /home/admin/user_backups/backup.sh

COPY THE FOLLOWING CONTENT and SAVE
DONT FORGET TO chmod 777 backup.sh and then run it like ./backup.sh

So what this will upload all your content to AMAZON s3, but before you do this please create your bucket and folder inside your bucket for example , I have a BUCKET NAME - YOURBUCKETNAMEHERE inside that bucket I have a folder called Directadmin

Code:
#!/bin/bash
S3_BUCKET=YOURBUCKETNAMEHERE
DATE=`date +%d%m%Y_%H%M`
BACKUP_LOC=/home/admin/user_backups/
LOG=/tmp/log_$DATE
mysql_backup(){
echo "Syncing files from $BACKUP_LOC to s3 bucket" >> $LOG
    s3cmd sync -r $BACKUP_LOC s3://$S3_BUCKET/Directadmin/
}
mysql_backup
exit 0

Enjoy !

UPDATED
 
Last edited:
In last codes (the real script) i suppose you made a little mistake.

This:

Code:
echo "Syncing files from $BACKUP_LOC to s3 bucket" >> /tmp/$LOG

Should be like this:

Code:
echo "Syncing files from $BACKUP_LOC to s3 bucket" >> $LOG

Cause the LOG variable is already pointed to /tmp/

Regards
 
Thanks for the catch

Would I run the daily backup from admin panel into the backup folder and then set a cronjob to run about an hour later for it to backup with S3?

Also what does mysql_backup(){ do?

John
 
Last edited:
Back
Top