Does anybody have a good solution for backing up /var on a live system?
All the recommendations I have seen so far have not taken into account the fact that /var holds live data and that restoring a file that was being simultaneously written to at the time it was captured is potentially disastrous. I wouldn't be caught dead backing up /var/lib/pgsql with a straight copy.
Generally I don't back up /var -- Things like Postgres should be backed up in accordance with the backup procedures in their respective manuals, and restored similarly (e.g. only an idiot would restore over a running instance).
Should you need to back up a specific subset of /var (like postgres' data directory, openldap's BDB directory, etc.) you should follow appropriate procedures outlined by the software vendor, or exercise good common sense (ensure the files are quiescent, etc)
I backup /var with
rsync
the way I do everything else, but my then run a secondary set of backups just for the databases using the database tools to do a data dump (or hot copy in some cases). Surprisingly the file system backups have proven useful more often that the database data backups.Also, the drives my databases are on all run file systems (or hardware) that allows snapshoting the entire file system at an instant in time. Doing this periodically is another great way to keep your data safe and sound.
But if for some reason you still want take consistent backup of entire /var , you may consider mount it as lvm partition and take an lvm snapshot: http://tldp.org/HOWTO/LVM-HOWTO/snapshotintro.html http://tldp.org/HOWTO/LVM-HOWTO/snapshots_backup.html
You mentioned postgres backup - for postgres to have consistent backup you can use pg_dump or combination of binary logs together with snapshot of postgres data directory (so called PITR) http://www.postgresql.org/docs/9.0/static/continuous-archiving.html#BACKUP-BASE-BACKUP
There is no silver bullet that will backup everything in one shot and make sure that all services data are consistent logically.