1

I have SSD and HDD hard drives on server.

SSD mounted to /

HDD mounted to /mnt/

I have 20 (planning more) sites with 5-20 GB content each.

I want to store

/home/user/domain1.com/ to SSD

/home/user/domain1.com/wp-content/uploads/ to HDD

And same for other domains

/home/user/domainN.com/ > SSD /home/user/domainN.com/wp-content/uploads/ > HDD

How to do it ?

I founded How do I mount sub-directory to a hard drive in Linux? , but its only for 1 drive/dir. Is there way to make some symlinks or something like this, which points to direct dir on other hard drive?

For example,

/home/user/domain1.com/wp-content/uploads/ points to /mnt/domain1.com/ /home/user/domain20.com/wp-content/uploads/ points to /mnt/domain20.com/

Thanks in advance!

wtfowned
  • 13
  • 3

1 Answers1

1

You doesn't need any "mounting" at all, you can simply symbolic-link the folder like that:

for domain in domain1.com domain20.com; do
  mkdir /mnt/$domain
  mv /home/user/$domain/wp-content/uploads/* /mnt/$domain
  rmdir /home/user/$domain/wp-content/uploads/ 
  ln -Ts /mnt/$domain /home/user/$domain/wp-content/uploads/ 
done

PS: it is possible to use bind mount also, but it's bit more cumbersome to setup automatically at boot, something like this should work:

for domain in domain1.com domain20.com; do
  mkdir /mnt/$domain
  mv /home/user/$domain/wp-content/uploads/* /mnt/$domain
  mount --bind /mnt/$domain /home/user/$domain/wp-content/uploads/
  echo "/mnt/$domain /home/user/$domain/wp-content/uploads/ none bind 0 0" >> /etc/fstab
done
silmaril
  • 471
  • 3
  • 9
  • Using ln -Ts will only work until reboot? – wtfowned Aug 05 '18 at 15:47
  • 1
    no a link symbolic or hard is like a file, once created it stay here – silmaril Aug 05 '18 at 21:14
  • About 2nd part of your answer, there is mistake. The right way is mount HDD dirs to SSD, than it works just fine! `mount --bind /mnt/hdd/domainN.com /home/user/domainN.com/wp-content/uploads` – wtfowned Aug 16 '18 at 14:53
  • indeed, i fixed the answer. I would still go for the link personnaly – silmaril Aug 21 '18 at 08:01
  • please note that with a bind mount you will "hide" the underlying files and folders on the target directory. Just make sure you have an empty folder you want to bind to. – Dennis Nolte Aug 21 '18 at 08:08
  • yup, that's one of the reason i prefer the link solution, anyway in both case the provided answer take care of moving file before creating the link / bind-mounting – silmaril Aug 21 '18 at 08:20