Excluding directories from tar, correctly
tar czf backup.tar.gz /data --exclude=/data/cache still contains cache.
--exclude matches the path as stored inside the archive, usually without the leading slash. Use --exclude='data/cache' or --exclude='*/cache'.
Details: one --exclude per pattern, not a comma list. Quote wildcards, or the shell expands them before tar sees them. Put --exclude before the paths being archived — GNU tar is more predictable that way. And check with tar tzf before trusting the archive.
A database directory that is being written will not give a consistent snapshot even with correct excludes. Use the database's own backup tool; tar is for static files.