Backup trick: moving user caches into /var/cache
Bear Giles | June 4, 2013I’ve been refining my backup scripts and want to share a quick trick.
There are many caches under the ~/.cache directory. Pretty much by definition caches only contain information that can be downloaded or recomputed again… and in fact it might cause problems if caches are restored. This is such an important point that tar(1) explicitly recognizes the CACHEDIR.TAG file as a marker if you specify the –excluded-caches tag and its variants.
One drawback to this approach is that you need to remember to set that flag. If you don’t your archives will explode in size.
Fortunately there’s a straightforward solution.
- Create /var/cache/users/user directory, change its ownership to user:user.
- Move chromium, evolution and mozilla caches (as appropriate):
- mv ~/.cache/chromium /var/cache/users/user/chromium.
- ln -s /var/cache/users/user/chromium /home/user/.cache/chromium.
- Move thunderbird cache (as appropriate):
- mv ~/.thunderbird /var/cache/users/user/thunderbird.
- ln -s /var/cache/users/user/thunderbird /home/user/.thunderbird.
As a developer I want to do the same thing to my maven repository at .m2/repository.
At this point routine backups of my home directory won't pick up the caches unless I add an explicit --dereference (or -h) flag. This makes backups faster and leaner.
It should go without saying that you should only do this with true caches that you can easily regenerate. You'll also want to document the need to recreate the /var/cache/users tree when restoring the system.