Backup

August 28th, 2006

I don’t trust computers to not suddenly explode and destroy everything I’ve ever created, and I’ve discovered what I believe to be the easiest and most foolproof way to backup my code, or other things for that matter. Email it to yourself automatically.

I use Subversion to manage my personal code library on a remote server, and since my goal is to always have everything important exist in two separate places, I have a compressed dump of the entire repository emailed to myself weekly. I delete the older versions, but since my email account has plenty of free space it’s not very urgent. This all seems straightforward, but I had to do a lot of research to find the right program to use, which I am now sharing with you. All you need to do is set up a cron job like this…


0 6 * * 0 (svnadmin dump ~/svn/repo/ | gzip --best > ~/svn/repo-backup.svndump.gz) 2>&1 | mutt -s 'repo-backup.svndump.gz '$(date +%m/%d/%Y) -a ~/svn/repo-backup.svndump.gz youremail@email.com

Obviously, replace the path to the repository and the email address to correct values, and put the backup file somewhere too. This particular job is scheduled to run at 6am on Sunday morning. The repository (~/svn/repo) is dumped and compressed (using gzip, at the highest level of compression) to the file "~/svn/repo-backup.svndump.gz". I use mutt to send the email with the file attached. The subject is the name of the file and the date the email was sent (to avoid grouping backup emails together). I also want messages that svnadmin outputs (which contain information on what was dumped, and possible error messages) to be the body of the email, but svnadmin sends the messages through stderr while mutt receives the body of the email through stdout. To fix this stderr is redirected as stdout after stdout has been used to compress the dumpfile. Isn’t Unix great?

Anyway, if you use Gmail, besides a lot of space to manage these backups, you can also make the process easier using plus-addressing. Let’s say your email is "bob@gmail.com", then set the email address in the example to "bob+backups@gmail.com". Set up a label called "Backups" in Gmail and a filter which automatically labels emails as "Backups" when they have been sent to "bob+backups@gmail.com". You can keep them out of your Inbox if you archive them with the filter as well.

Some other important things…

  • Keep in mind there are size limits for attachments in emails, but this isn’t much of a problem as long as your repository stays fairly small (and full of text files).
  • You don’t need to send them to one address, check the manual page for mutt for more information.
  • Using bzip2 rather than gzip would be a better idea, as bzip2 has recovery features if something goes wrong, but currently Gmail has a major bug when viewing emails with bzip2-compressed files attached. These emails are improperly handled and won’t open through Gmail.
  • I prefer to use a svnadmin dump since I won’t be making any commits at exactly that moment, but more active repositories should probably dump a copy of the repository using svnadmin hotcopy instead as a safety precaution.

The future of computers

August 25th, 2006

Amazon is onto something. It’s like a VPS on steroids. I’m not joking when I say that this is the future of the Internet hosting, or more accurately, computer processing in general.

I get my feed updates via Gmail (it’s a long story) and I got this one two weeks ago. I was planning on posting it right away, but then I figured it’d be in bad taste if the world actually ended on August 22nd. Boy would my face be red! Be sure to the sidebar.

Speaking of Boing Boing… FC64 got boingboinged.

Browser history bug

August 22nd, 2006

This is clever. You know that links using the CSS :visited pseudo-class change if you’ve visited the linked page. Did anybody think of using that to tell where you’ve been? It’s so obvious now. I imagine several browsers will issue fixes for this down the line, probably by denying the use of :visited for other domains.

Zlib experiments

August 11th, 2006

I’m getting tired, but I have the following for you all, a working sample of this whole compression thing that I’ve become interested in lately. You’ll need Python for this. You should also know how to compile and debug an AS3 class. Save the following code sample as “zlib.py” and put it along with the file you wish to compress somewhere. The file you want to compress should be a text file for this example, although any file will work.

[Python]
#!/usr/bin/env python

import zlib
import os, sys

# Make windows output as binary
if sys.platform == “win32”:
import msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)

if len(sys.argv) < 2:
sys.exit(“No filename given”)
else:
f = open(sys.argv[1], “rb”)

deflate = zlib.compressobj(9)

while 1:
buf = f.read(1024);
if buf:
sys.stdout.write(deflate.compress(buf))
else:
break;
sys.stdout.write(deflate.flush(zlib.Z_FINISH));
[/Python]

Open the directory where you put the files in the command line.

  • If you’re using Windows then type “zlib.py filename > compressed.zlib” at the command line. Replace “filename” with the name of the file you want to compress.
  • If you’re using Mac OS X (or another Unix OS) first make sure you can execute the file, then type “./zlib.py filename > compressed.zlib” at the command line. Replace “filename” with the name of the file you want to compress.

Save the following Actionscript 3.0 file as “Testify.as” and compile it.

[Actionscript]
package {
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import flash.events.Event;
import flash.events.IOErrorEvent;

public class Testify {
static private var url:String = “compressed.zlib”;

private var urlLoader:URLLoader;

public function Testify() {
trace(“Loading “+url);
urlLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(Eve​nt.COMPLETE,onComplete);
urlLoader.addEventListener(IOE​rrorEvent.IO_ERROR,onError);
urlLoader.load(new URLRequest(wadUrl));
}
private function onComplete(e:Event):void {
trace(“Loaded”);
var data:ByteArray = urlLoader.data;
urlLoader.data = null;
urlLoader.close();
urlLoader = null;

data.uncompress();

data.position = 0;
trace(data.readUTFBytes(data.b​ytesAvailable));
}
private function onError(e:Event):void {
trace(“Error”);
}
}
}
[/Actionscript]

Alright, now make sure the “compressed.zlib” is in the same folder as your SWF file, and use either the Flex debugger (flc.exe) or (if you’re using Eclipse) debug the class as an Actionscript project. Your output should be the original file.

Andre Michelle is my personal Flash hero, I find I’m always interested in the things he’s doing. Anyway, his steady obsession with making audio on-the-fly from within Flash has come to fruition and it’s just plain cool. He uses mod files with ByteArray and has managed to hack together a capable audio player. I experimented with mod files but favored midi files instead in a downright weird project I had going a while back. People seem to be slowly realizing how much ByteArray is going to change how people do advanced techniques in Flash.

I’m in the midst of an effort to work out some way to decompress files from within Flash with some help from the people at Flashcoders, although it’s going to be tricky. Basically, you have zip (or gzip) files and Flash, they both use the same compression techniques, but a minor difference makes them completely incompatible normally. But I’ll be damned if that stops me.

This project is DOOMED

August 8th, 2006

This took me about a day. It’s not a pre-rendered image, it’s been grabbed directly from an old-school shareware Doom wad file and imported into Flash.

It’s harder than it looks.

Virtual Music

August 2nd, 2006

I made a poor attempt at a blog on another site a while back, it failed when I lost several drafts in a row to my twitchy browser-closing finger. Plus it was slow as hell. I’m bringing an article over that I always liked about emulated music, which is music taken directly from a video game in its original format. Ironically I rarely listen to video game music, I just like the fact that I can when I feel like it.

This post covers all these formats and more.

  • NES
  • SNES
  • Genesis
  • Gameboy
  • Gameboy Advance
  • Nintendo 64
  • Playstation
  • Playstation 2
  • why Gamecube and Xbox aren’t on this list