After admitting that of all things Microsoft offers 25GB cloud storage for its Windows Live subscribers I will walk through my latest preliminary experiments regarding backup of important data using the using the Amazon Advanced Web Services. The storage is not free but quite cheap at around 0.1$ per GB and month.
If you use Windows and MS Office a lot use Skydrive and don’t read on 😉 There are posts which describe how to map the Skydrive like a local harddisk using MS Word.
On the long run I would like to mount a EBS storage like a local file tree, probably using WebDAV, but this is my first successful preliminary solution. s3cmd does not work for me.
Using Ubuntu/Linux rsync is a well established, reliable and easy to use tool to keep data between locations in sync. The following post marries rsync with an Elastic Cloud (EC2) server instance for an hour or some. One has to set up the so called rsync daemon and attach a persistent Elastic Block Storage.
This is another post. I will link to it later. There will also be a small script. There are some holes in this tutorial, only the direct configuration of the rsync daemon (including the script) is complete and working. I filled in some hints how to get to this stage. But will write follow ups on that.
System Out provided a nice tutorial of how to set up the rsync in demon mode on a server which listens for clients to sync their data.
Here is my version of it, with a short script at the end which should do the job.
Prerequisites
Of course you need to have rsync on both machines (the server and the client); since both are Ubuntu this is the case.
I will write another post on how to start the server. It is completely possible and quite intuitive to achieve it in the Amazon web interface. When the server is running and an extra EBS harddisk is attached you have to connect to the server using ssh
ssh -i PATH/TO/YOUR/PEM-KEY-FILE ubuntu@ec2-xxx-xx-xxx-xxx.compute-1.amazonaws.com
Mount the persistent drive
There are some posts about the advantages of the xfs filesystem, so I sticked to it. Alestic recommends it for all persistent EC2 cloud disks and I trust they know what they are doing. But xfs is not per default included in the Ubuntu micro instance I use for my backups. That said, in the SSH shell:
sudo apt-get install -y xfsprogs
sudo modprobe xfs
If the backup volume is newly created then format it:
sudo mkfs.xfs /dev/xvdb
Note: Only the first time. Otherwise you wipe your data, of course. Note also the device name. I attached it as /dev/sdb. Though it showed up in the Ubuntu Oneiric i386 t1.micro instance as /dev/xvdb.
Now mount the volume
echo "/dev/xvdb /media/backup xfs noatime 0 0" | sudo tee -a /etc/fstab
sudo mkdir /media/backup
sudo mount /media/backup
sudo chown ubuntu:ubuntu /media/backup
sudo chmod 777 /media/backup
Configuration files
On the server machine you need to set up a daemon to run in the background and host the rsync services.
Before you start the daemon you need to create some rsync daemon configuration files in the /etc directory.
Three files are necessary:
- /etc/rsyncd.conf, the actual configuration file,
- /etc/rsyncd.motd, Message Of The Day file (the contents of this file will be displayed by the server when a client machine connects) and
- /etc/rsyncd.scrt, the username and password pairs.
To create the files on the server:
sudo nano /etc/rsyncd.conf
Now enter the following information into the rsyncd.conf file:
motd file = /etc/rsyncd.motd
[backup]
path = /media/backup
comment = the path to the backup directory on the server
uid = ubuntu
gid = ubuntu
read only = false
auth users = ubuntu
secrets file = /etc/rsyncd.scrt
Hit Ctrl-o to save and Ctrl-x to close nano.
The uid, gid, auth users are the users on the server. In the ssh session on the ec2 instance the user is ubuntu.
The format for the /etc/rsync.scrt file is
username:whatever_password_you_want
Use nano to put some arbitrary text into the /etc/rsync.motd.
Now you should have all the configuration information necessary, all that’s left to do is open the rsync port and start the daemon.
To open the port, open the /etc/default/rsync file, i.e.,
sudo nano /etc/default/rsync
and set RSYNC_ENABLE=true.
Here you might also specify another port than the default 873. Remember to open the port in the security group. Either with the AWS web interface in your browser or in the shell using the ec2-api-tools:
ec2-authorize default -p 873
Now to start the daemon,
sudo /etc/init.d/rsync restart
and exit the SSH session.
Syncing a folder
Now you can use your local shell to push some folders or files to the server. Update the server side from the client machine with ec2-api-tools installed:
EXIP=`ec2din | grep INSTANCE | grep -v terminated |awk '{print $4}'`
rsync -auv /home/rforge/articles ubuntu@$EXIP::backup/
$EXIP would be the server ip address
This gets the IP of the server from the ec2-api-tool and passes it to RSYNC.
Otherwise you have to remember the IP of your instance from the web interface and substitut it for xxx.xxx.xxx.xxx:
rsync -auv /PATH/TO/FOLDER/ ubuntu@$xxx.xxx.xxx.xxx::backup/
::backup has to match [backup] in the /etc/rsyncd.conf file. You will see the rsyncd.motd message and get prompted for the password in the rsyncd.scrt file. Then rsync starts the upload.
A Script
The following script should do the daemon setup after connecting to the server via ssh and mounting the volume. Keep me posted if something does not work.
echo "motd file = /etc/rsyncd.motd
[backup]
path = /media/backup
comment = the path to the backup directory on the server
uid = ubuntu
gid = ubuntu
read only = false
auth users = ubuntu
secrets file = /etc/rsyncd.scrt" > rsyncd.conf
sudo mv rsyncd.conf /etc/
#
sudo echo "Greetings! Give me the right password! Me want's it!" > rsyncd.motd
sudo mv rsyncd.motd /etc/
#
sudo echo "ubuntu:YourSecretPassword" > rsyncd.scrt
sudo mv rsyncd.scrt /etc/
#
sudo chmod 640 /etc/rsyncd.*
sudo chown root:root /etc/rsyncd.*
#
## enable demon mode in the /etc/default/rsync file
sudo cat /etc/default/rsync | sed 's/RSYNC_ENABLE=false/RSYNC_ENABLE=true/g' > rsync
sudo mv rsync /etc/default/
sudo chown root:root /etc/default/rsync
sudo chmod 644 /etc/default/rsync
#
sudo /etc/init.d/rsync restart # start the demon
Nice post. Thanks for sharing.
There is an easier way to back up your data: Duplicati. Duplicati is a backup tool that stores encrypted, incremental, compressed backups on remote file servers. Internally it uses the rsync algorythm to create the incremental backup (rsync, rdiff) and it has encryption and support for various cloud storage services built in (SkyDrive, AWS, Rackspace, …) but also standard transfer protocols like SSH, WebDAV, FTP.
A few days ago a Ubuntu (Debian) package has been released. http://www.duplicati.com/news/packagesforubuntudebianredhatandothers
Try it out and tell us what you think!
I started to use Duplicati yesterday and are very pleased so far:
I did not try to recover from backup which is the important part 😉 When I find the time I will do a simulated recovery. When Duplicati lives up to its promise (which I do not doubt) it is exactly what I was looking for all the time…
I would like to see it included in Xubuntu (my favorite distro) by default – that would save a lot of people a lot of headache, I suppose….
Extremely please with Duplicati! Using it with Dreamhost Dreamobjects Storage