Setup a Backup Folder on Ubuntu using Amazon S3

These instructions show you how to use s3fs to have a path on your Ubuntu server that keeps data on Amazons S3 solution. This can be used as a backup path, so any files added here are stored on a remote file system.

The first step is to create a bucket in your Amazon S3 account and get the security credentials. It is suggested to use IAM to create a user with limited access to Amazon Account features.

Download and install s3fs. This assumes the latest version is 1.64 – but you should check and change the version as required (here)

apt-get install build-essential libfuse-dev fuse-utils libcurl4-openssl-dev libxml2-dev mime-support
wget 
tar xvzf s3fs_.tar.gz
cd s3fs-_
./configure --prefix=/usr
make && make install

Create the following file

vim /etc/passwd-s3fs

and add the following contents (replace with your own values!)

bucketName:accessKeyId:secretAccessKey

Change the permissions

chmod 640 /etc/passwd-s3fs

Next, create the following file

vim /etc/init.d/s3backup

With these contents (replace the bucket name and destination with your own values). The Destination path is simply an empty folder anywhere in your file system – just like you would mount any drive.[

# ! /bin/sh
# /etc/init.d/s3backup

bucketName='YOURBUCKETNAME'
mountDestination='ABSOLUTE DESTINATION FOLDER'

case "$1" in
  start)
  echo "mounting '$bucketName' to '$mountDestination'"
  /usr/bin/s3fs -o allow_other $bucketName $mountDestination
  ;;

mount)
  echo "mounting '$bucketName' to '$mountDestination'"
  /usr/bin/s3fs -o allow_other $bucketName $mountDestination
  ;;

stop)
  echo "unmounting '$bucketName' from '$mountDestination'"
  umount s3fs
  ;;

unmount)
  echo "unmounting '$bucketName' from '$mountDestination'"
  umount s3fs
  ;;

*)
echo "Usage: /etc/init.d/s3backup {mount|unmount}"
exit 1
;;
esac

And run the following commands

chmod 755 /etc/init.d/s3backup
update-rc.d -f s3backup defaults

This make it executable and makes it into a startup script respectively.

Leave a comment

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