As I recall, if you have a MacBook, iMessage syncs your messages and stores them in a file named ~/Library/Application Support/MobileSync/Backup
That file or files (my notes don't say number or the names of files) is just a SQL database which can be queried with the sqlite client, or exported into a more friendly format.
This solution worked for me about 5 years ago; I don't know if Apple still allows this.