I mentioned a few days ago that there were a few ways to lose your tags in OS X. I began working on the best solution I could come up with for now: TagBak.

TagBak is a command line utility (inspired by Michael Simons) which saves all the tags in a directory and its subdirectories in a stash file. This file can be updated before any backup, maintaining a snapshot of tags, potentially versioned (depending on your backup strategy). When TagBak is used to restore tags, it will re-apply the saved tags to all affected files.

It can also be used with Git repositories and the like. Run tagbak store once, and add the resulting .metadata.stash file to the repository. Use hooks (probably post-commit and post-receive) to update it before pushing and restore after pulling from another endpoint.

See the project page for installation and usage instructions.