AWS Backup Linux

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
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!)


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


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

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

  echo "unmounting '$bucketName' from '$mountDestination'"
  umount s3fs

  echo "unmounting '$bucketName' from '$mountDestination'"
  umount s3fs

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

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 Reply