Remote backups are crazily important for Colin and I with our nomadic lifestyle. We consider ourselves very lucky that we haven’t had our laptops stolen or destroyed in 5 years of travel. We take precautions: we lock our doors, keep our laptops out of sight, and try to give off an air of “thrifty backpackers” while actually carrying around $6,000 worth of electronics. But if it should ever happen, we could be up and working again within 24 hours thanks to offsite backups.
I use Dropbox for large files and Google Drive for documents (both free to a point), and for code I use offsite version control software. There are free hosting services for Git… but after working with it on several projects over many years I still don’t fully understand Git and consistently screw up commits. I am much more comfortable with older, simpler Subversion. But there are no free or even reasonably-priced hosting options for svn projects unless you make them open source.
However, Amazon is offering free linux EC2 servers with 30gb ssd hard drive space. For a relatively small project like Rebuild with only a couple contributors and few branches, that’s more than enough, and the equivalent hosted option costs $50/month or more. The trick is configuring it. This took me a few hours, some false starts and useful tutorials. You do need to be familiar with Linux. I documented the process for my own uses, but here it is for you:
Creating an EC2 instance and SSHing in
Create a new EC2 instance
They won’t charge you unless you go beyond their free tier
I chose to put mine in Oregon (us-west-2)
Check “only free” and pick a freebie amazon linux ami
I used amzn-ami-hvm-2014.09.1.x86_64-ebs (ami-b5a7ea85)
Next page, choose max free (30gb) ssd
Next page, open HTTP port to all (0.0.0.0) – SSH is already open by default
Complete and launch your instance
Create a new key pair when prompted and download the .PPK file from amazon.
Visit the EC2 dashboard, instance should be Running and status checks 2/2
Record your instance IP (YOUR_INSTANCE_IP)
Download Putty
SSH into your instance using the PPK from amazon (guide)
Default amazon AMI SSH username is ec2-user, no password
ec2-user@YOUR_INSTANCE_IP
You’re in! Putty hint: right-click to paste clipboard contents.
Installing software
Update pre-installed software:
# sudo yum update -y
Visit the public ip in your browser: http://YOUR_INSTANCE_IP
should see Amazon Linux AMI Test Page if Apache is installed and running
If Apache is not installed (guide):
# sudo yum groupinstall -y "Web Server" "MySQL Database" "PHP Support"
# sudo yum install -y php-mysql
# sudo service httpd start
Install subversion and mod_dav_svn (should see a long list of all changes):
# sudo yum –y install mod_dav_svn
# sudo yum –y install subversion
Edit the Apache configuration file for subversion:
# sudo vi /etc/httpd/conf.d/subversion.conf
Replace any subversion.conf content with:
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
<Location /repos>
DAV svn
SVNParentPath /var/www/svn
# Limit write permission to list of valid users.
AuthType Basic
AuthName "Authorization Realm"
AuthUserFile /var/www/svn-auth/passwd
AuthzSVNAccessFile /var/www/svn-auth/access
Require valid-user
</Location>
Create the directory which will contain the subversion repository:
# sudo mkdir /var/www/svn
Create the directory which will contain the permissions files.
# sudo mkdir /var/www/svn-auth
Create the permission file:
# sudo vi /var/www/svn-auth/access
And fill it with (replace sarah, colin, guest with your usernames):
[/] sarah = rw colin = rw guest = rw
Create and add to the password file (use -c the first time to create)
# sudo htpasswd -cb /var/www/svn-auth/passwd sarah SARAHSPASSWORD
# sudo htpasswd -b /var/www/svn-auth/passwd colin COLINSPASSWORD
# sudo htpasswd -b /var/www/svn-auth/passwd guest GUESTSPASSWORD
Create a repository (REPONAME is the name of your repository eg rebuild):
# cd /var/www/svn
# sudo svnadmin create REPONAME
Change files authorization (again after creating new repos too):
# sudo chown -R apache.apache /var/www/svn /var/www/svn-auth
# sudo chmod 600 /var/www/svn-auth/access /var/www/svn-auth/passwd
Start apache web server:
# sudo service httpd restart
Will complain about determining domain and using 127.0.0.1, that’s ok
To make sure apache always starts on boot:
# sudo chkconfig httpd on
# sudo chkconfig --list
Should show 2:on 3:on 4:on 5:on for httpd
Verify the subversion repo by opening in a browser:
http://YOUR_INSTANCE_IP/repos/REPONAME
You’re done! Connect via Tortoise or your fav svn client using the url above.
Other operations
To copy from an older repo including revisions:
# sudo svnadmin dump /var/www/svn/REPONAME > /tmp/REPONAME.svn
(copy the file to the new server then)
# sudo svnadmin load /var/www/svn/REPONAME < /tmp/REPONAME.svn
To connect a backup mirror on another (non-free) EC2 server with the same setup (guide)
First make revisions editable in the mirror repo:
# sudo echo '#!/bin/sh' > /var/www/svn/REPONAME/hooks/pre-revprop-change
# sudo chmod 755 /var/www/svn/REPONAME/hooks/pre-revprop-change
Then initialize the mirror from the old one:
# sudo svnsync init file:///var/www/svn/REPONAME http://YOUR_INSTANCE_IP/repos/REPONAME
Should see "Copied properties for revision 0."
Then copy the data including all revisions:
# sudo svnsync sync file:///var/www/svn/REPONAME
Can use this to make nightly backups to another server
Leave a Reply