Dumping a Linux console scrollback buffer?

We would like to save the output of a program run on a Linux console which spans many lines. Unfortunately it wasn't logged or run under screen, or any other way that lets us easily capture the output. The best method we've been able to come up with so far is:

Log into the machine via a separate SSH session
In the console session, page to the top of the buffer
Repeat:
  In the SSH session, run "cat /dev/vcs >> screendump.txt"
  In the console session, page down one screen
Dump the final screen in the SSH session

Is there a better way? It seems like if the VC memory were contiguous and you knew where it was you could use dd to pull the console text directly out of kernel memory and into a file.


Solution 1:

setterm can dump the contents of a Linux virtual console:

setterm -file log.txt -dump [ttynumbers]

However, it does not have access to the scrollback buffer, only to what's currently displayed.