What’s this about?
Data security and backups are very important aspects when you work with servers, especially if you are using cloud infrastructure. I am using AWS(Amazon Web Services) as my preferred IaaS, so the following how-to is tailored for Amazon EC2 instances using EBS as storage for the web sites files. On my instance I have Ubuntu 10.04 LTS installed and on top of it I run ISPConfig 3.0.4(latest version at the moment I write this article). Some of the programs required to run this setup were already installed, but it should be pretty obvious if you miss anything. If you need help you can either leave a comment or contact me via email.
The following setup will allow you to create an EBS using EXT4 as file system, with quota enabled on it(for ISPConfig) and weekly backups of the EBS. In case of instance failure you should be able to launch a new instance and attach the EBS, without losing any web sites files. In case of EBS failure you can recreate one from the most recent snapshot.
Create an EBS in the same zone as your instance and attach it to your instance as /dev/sdf. This can be easily done from AWS Management Console.
sudo apt-get install xfsprogs
Create EXT4 filesystem on /dev/sdf
sudo mkfs.ext4 /dev/sdf
Now mount it temporarily
sudo mkdir /mnt/ebs sudo mount /dev/sdf /mnt/ebs
Stop the apache2 web server and copy the files to /mnt/ebs
sudo service apache2 stop cd /mnt/ebs sudo cp -rp /var/www/* .
touch quota.user quota.group sudo chmod 600 quota.*
Add the entry to /etc/fstab
/dev/sdf /var/www ext4 noatime,nobootwait,usrjquota=quota.user,grpjquota=quota.group,jqfmt=vfsv0 0 0
Unmount the EBS and remount it to /var/www
sudo umount /dev/sdf sudo mount /dev/sdf /var/www -o noatime,usrjquota=quota.user,grpjquota=quota.group,jqfmt=vfsv0
sudo quotacheck -avugm sudo quotaon -avug
Start the apache2 web server and check that the web sites are working properly
sudo service apache2 start
Install ec2-consistent-snapshot script for weekly backups of EBS
sudo add-apt-repository ppa:alestic sudo apt-get update sudo apt-get install -y ec2-consistent-snapshot
Prepare first snapshot(I assume the cron will run as root user, hence I create the awssecret file in /root directory)
sudo touch /root/.awssecret sudo chmod 600 /root/.awssecret
Edit .awssecret and add following lines, in this order, replacing ACCESS_KEY_ID and SECRET_ACCESS_KEY with your own, both can be found under Account->Security Credentials:
Test the snapshot creation with debug mode activated, replace VOLUME_ID with the right volume ID:
sudo ec2-consistent-snapshot --debug --description "snapshot $(date +%Y-%m-%d-%H:%M:%S)" --freeze-filesystem /var/www vol-VOLUME_ID
If everything went well you should be able to see your new snapshot in the AWS Management Console.
Finally add this to your root crontab (by running sudo crontab -e):
@weekly /usr/bin/ec2-consistent-snapshot --debug --description "snapshot $(date +'%Y-%m-%d %H:%M:%S')" --freeze-filesystem /var/www vol-VOLUME_ID>>/var/log/backup.log 2>&1
Make sure you put the correct VOLUME_ID!
This should be all, you now have all your web sites on EBS, quota is enabled and weekly backups enabled. I think I pretty much nailed everything you need in order to perform this setup, but if there are any issues feel free to leave a comment. Also I love getting feedback so if you found this article useful leave a comment also 🙂