Skip to main content
added 164 characters in body
Source Link
cas
  • 84.4k
  • 9
  • 136
  • 205

One solution is to create a sub-volume just for the data you DON'T want backed up and then move-and-symlink the directories

For example, assuming all the files & directories you want to exclude (except for /swapfile) are in your home directory, which is either a sub-volume itself or part of a sub-volume for all of /home:

NOTE: I would not recommend trying to execute the following as-is. it's intended as shell-like pseudo-code that you will need to adapt to your circumstances.

cd /
sudo btrfs subvolume create caches
sudo mkdir /caches/rainer /caches/root

# swapfile, presumably owned by root
sudo swapoff /swapfile
sudo mv /swapfile /caches/root/
sudo ln -s /caches/root/swapfile /
sudo swapon /swapfile
# BTW, instead of symlinking, a better alternative for this
# file would be to edit /etc/fstab to use the new location
# of the swapfile.

sudo chown youruser:yourgroup /caches/rainer
cd ~/

# Before proceeding you should stop all processes
# that have open files in the directories to be moved,
# e.g. web browsers, file viewers (such as epub or pdf), and 
# anything else that uses the cache director{y,ies} and is
# currently running.

for d in .cache/ cache/ [Tt]rash/; do
  mv "$d" /caches/rainer/
  ln -s "/caches/rainer/$d/" ./
done

# you can restart your stopped processes now

NOTE: you may run into a problem with [Tt]rash/, depending on the file browser you use and how it deals with the trash dir being a symlink rather than a directory. If that happens see if you can configure your file browser to use /caches/rainer/trash (but that might not be possible because most will use one hard-coded trash dir per filesystem).

In fact, it wouldn't hurt to do similar for all programs that use ~/.cache and ~/cache - move-and-symlink is a time-tested method that works and has worked for decades, but that's no reason to assume that software devs won't do stupid and lazy things when they get the chance.

One solution is to create a sub-volume just for the data you DON'T want backed up and then move-and-symlink the directories

For example, assuming all the files & directories you want to exclude (except for /swapfile) are in your home directory, which is either a sub-volume itself or part of a sub-volume for all of /home:

cd /
sudo btrfs subvolume create caches
sudo mkdir /caches/rainer /caches/root

# swapfile, presumably owned by root
sudo swapoff /swapfile
sudo mv /swapfile /caches/root/
sudo ln -s /caches/root/swapfile /
sudo swapon /swapfile
# BTW, instead of symlinking, a better alternative for this
# file would be to edit /etc/fstab to use the new location
# of the swapfile.

sudo chown youruser:yourgroup /caches/rainer
cd ~/

# Before proceeding you should stop all processes
# that have open files in the directories to be moved,
# e.g. web browsers, file viewers (such as epub or pdf), and 
# anything else that uses the cache director{y,ies} and is
# currently running.

for d in .cache/ cache/ [Tt]rash/; do
  mv "$d" /caches/rainer/
  ln -s "/caches/rainer/$d/" ./
done

# you can restart your stopped processes now

NOTE: you may run into a problem with [Tt]rash/, depending on the file browser you use and how it deals with the trash dir being a symlink rather than a directory. If that happens see if you can configure your file browser to use /caches/rainer/trash (but that might not be possible because most will use one hard-coded trash dir per filesystem).

In fact, it wouldn't hurt to do similar for all programs that use ~/.cache and ~/cache - move-and-symlink is a time-tested method that works and has worked for decades, but that's no reason to assume that software devs won't do stupid and lazy things when they get the chance.

One solution is to create a sub-volume just for the data you DON'T want backed up and then move-and-symlink the directories

For example, assuming all the files & directories you want to exclude (except for /swapfile) are in your home directory, which is either a sub-volume itself or part of a sub-volume for all of /home:

NOTE: I would not recommend trying to execute the following as-is. it's intended as shell-like pseudo-code that you will need to adapt to your circumstances.

cd /
sudo btrfs subvolume create caches
sudo mkdir /caches/rainer /caches/root

# swapfile, presumably owned by root
sudo swapoff /swapfile
sudo mv /swapfile /caches/root/
sudo ln -s /caches/root/swapfile /
sudo swapon /swapfile
# BTW, instead of symlinking, a better alternative for this
# file would be to edit /etc/fstab to use the new location
# of the swapfile.

sudo chown youruser:yourgroup /caches/rainer
cd ~/

# Before proceeding you should stop all processes
# that have open files in the directories to be moved,
# e.g. web browsers, file viewers (such as epub or pdf), and 
# anything else that uses the cache director{y,ies} and is
# currently running.

for d in .cache/ cache/ [Tt]rash/; do
  mv "$d" /caches/rainer/
  ln -s "/caches/rainer/$d/" ./
done

# you can restart your stopped processes now

NOTE: you may run into a problem with [Tt]rash/, depending on the file browser you use and how it deals with the trash dir being a symlink rather than a directory. If that happens see if you can configure your file browser to use /caches/rainer/trash (but that might not be possible because most will use one hard-coded trash dir per filesystem).

In fact, it wouldn't hurt to do similar for all programs that use ~/.cache and ~/cache - move-and-symlink is a time-tested method that works and has worked for decades, but that's no reason to assume that software devs won't do stupid and lazy things when they get the chance.

Source Link
cas
  • 84.4k
  • 9
  • 136
  • 205

One solution is to create a sub-volume just for the data you DON'T want backed up and then move-and-symlink the directories

For example, assuming all the files & directories you want to exclude (except for /swapfile) are in your home directory, which is either a sub-volume itself or part of a sub-volume for all of /home:

cd /
sudo btrfs subvolume create caches
sudo mkdir /caches/rainer /caches/root

# swapfile, presumably owned by root
sudo swapoff /swapfile
sudo mv /swapfile /caches/root/
sudo ln -s /caches/root/swapfile /
sudo swapon /swapfile
# BTW, instead of symlinking, a better alternative for this
# file would be to edit /etc/fstab to use the new location
# of the swapfile.

sudo chown youruser:yourgroup /caches/rainer
cd ~/

# Before proceeding you should stop all processes
# that have open files in the directories to be moved,
# e.g. web browsers, file viewers (such as epub or pdf), and 
# anything else that uses the cache director{y,ies} and is
# currently running.

for d in .cache/ cache/ [Tt]rash/; do
  mv "$d" /caches/rainer/
  ln -s "/caches/rainer/$d/" ./
done

# you can restart your stopped processes now

NOTE: you may run into a problem with [Tt]rash/, depending on the file browser you use and how it deals with the trash dir being a symlink rather than a directory. If that happens see if you can configure your file browser to use /caches/rainer/trash (but that might not be possible because most will use one hard-coded trash dir per filesystem).

In fact, it wouldn't hurt to do similar for all programs that use ~/.cache and ~/cache - move-and-symlink is a time-tested method that works and has worked for decades, but that's no reason to assume that software devs won't do stupid and lazy things when they get the chance.