Automatically zipping, sharing, moving demo’s of Source-based games

I run a bunch of gameservers for my TF2 clan. On these servers there’s a Source TV that automatically records demo’s of matches. After a match it’s nice to be able to download such a demo and see where your team can improve.

To make these demo’s available to everyone you have to put them on a website somewhere, and doing this manually is annoying. Also, demo’s are easily to compress, so you would like them to get zipped before offering them for a download.

So I wrote a Ruby script that:

  • Uses 7zip to compress all .dem files in directories you specify
  • Removes the original .dem files
  • Moves all the .7z files to predifined directories
  • Restarts the servers when this is done

The result is a nice download area at our server

--------------------------------------
Starting demozip process
--------------------------------------
Start processing directory /location/of/server/1
--------------------------------------
--------------------------------------
Start processing directory /location/of/server/2
--------------------------------------
Zipping auto-20081209-2157-arena_badlands.dem from
/location/of/server/2 and moving to /var/www/demos/2
Finished zipping in 0 seconds...
Removing /location/of/server/2/auto-20081209-2157-arena_badlands.dem
Zipping auto-20081209-2212-arena_ravine.dem from
 /location/of/server/2 and moving to /var/www/demos/2
Finished zipping in 0 seconds...
Removing /location/of/server/2/auto-20081209-2212-arena_ravine.dem
Zipping auto-20081209-2231-arena_well.dem from
 /location/of/server/2/tf and moving to /var/www/demos/2
Finished zipping in 0 seconds...
Removing /location/of/server/2/auto-20081209-2231-arena_well.dem
Zipping auto-20081209-2240-ctf_bball2.dem from
 /location/of/server/2 and moving to /var/www/demos/2
Finished zipping in 21 seconds...
Removing /location/of/server/2/auto-20081209-2240-ctf_bball2.dem
--------------------------------------
Start processing directory /location/of/server/3
--------------------------------------
Zipping auto-20081209-2049-cp_granary.dem from
 /location/of/server/3 and moving to /var/www/demos/3
Finished zipping in 0 seconds...
Removing /location/of/server/3/auto-20081209-2049-cp_granary.dem
Zipping auto-20081209-2131-cp_granary.dem from
 /location/of/server/3 and moving to /var/www/demos/3
Finished zipping in 28 seconds...
Removing /location/of/server/3/auto-20081209-2131-cp_granary.dem
-----------------------------------------------------------------
Finished zipping and moving all demo's in 52 seconds
-----------------------------------------------------------------
Demo's diskusage is now:
197M	/var/www/demos/1
80M	/var/www/demos/3
71M	/var/www/demos/2
348M	/var/www/demos
-----------------------------------------------------------------
Space left on drive:
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             141G   12G  123G   9% /

You can get the script here

It’s written in Ruby and uses RubyGems and a rubygem called Duration for pretty output of how long it took to make the zips and such.

You might need to do the following to get it to work

sudo apt-get install ruby ruby1.8 rubygems

sudo gem install duration

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>