Backup SugarCRM to Amazon S3

Our Sugar environment is in Amazon so why not back the thing up in Amazon. We also have decided to sync the cache/uploads folder so that we can scale sideways, that’s the next thing to do 🙂

You will need s3cmd installed to use this, handily s3cmd installation instructions

As per usual this will change as little errors get taken care of so please note that this is the 1st effort at the script so be a bit careful

 # Backup Script
 #DATE=`date +%Y-%m-%d_%Hh%Mm`
 DATE=`date +%Y-%m-%d`
# Directory for logs
 # Use the standard log file directories
 # Create required directories
 if [ -d "$LOGDIR/$S3LOGDIR" ]; # Check log Directory exists.
 echo "directory exists"
 echo "the directory does not exist"
 mkdir -p "$LOGDIR/$S3LOGDIR"
 #Clean up the error file before the script starts
 rm -f $LOGDIR/$S3LOGDIR/s3errfile
 # Change the directories below
# Directory to backup
#Main S3 bucket
#Directories that will be synced using s3
 #File Names
 #End the variables that need entering
#Backup the main directories, leave the cache upload directory
#Check that the S3 connection is available
 s3cmd ls $S3Bucket/ 2>&1>$LOGDIR/$S3LOGDIR/s3errfile
 if [[ -s $LOGDIR/$S3LOGDIR/s3errfile ]] ; then
 echo "connection OK"
 echo "S3 bucket connection failed"
 exit 1
 fi ;
#tar the dirctory excluding the cache/upload folder as this will be
#use the s3cmd rsync command as this is where the uploaded document
#are stored
tar -cvf $BACKUPFILE --exclude "cache/uploads*" --exclude "cache/uploads/*" $BACKUPSRCDIR
#Put the tar file into S3 for safe keeping
s3cmd put $BACKUPFILE $S3Bucket/$S3LiveBucket/
#Clear the backup file
#Sync the big folders to S3
s3cmd sync $LocalSyncDir $S3Bucket/$S3SyncBucket/

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s