-   Linux - Newbie (
-   -   safely mv directory to another partition and replace with symlink (

mmtrebuchet 01-30-2012 02:33 PM

safely mv directory to another partition and replace with symlink
Hi, all.
So I'm running a little Slackware LAMP server.
I have a couple partitions:


Filesystem  Size  Mounted on
/dev/root    49G  /
/dev/md1    147G  /www #website and stuff

I'd like to store my databases on /www, as it's raided and not likely to be accidentally formatted if I reinstall the OS.
Currently, they're stored in /var/lib/mysql.

What I'd like to do is something like
mv /var/lib/mysql /www/mysql
and then
ln -s /www/mysql /var/lib/mysql
(I probably messed up that syntax.)

Before I do something really stupid, though, I want to filter this idea with you guys.
So, uh, do I have the right mv and ln syntax? Will mysql explode when it encounters a symlink?
Or, even better, is there an option in my.cnf or a similar file that lets me change the directory properly? I didn't see anything, but mysql has a huge man page...
(Currently, there's no data I cherish in the databases, but I figure I should probably learn to do this right before I have to move actually valuable data.)

Tinkster 01-30-2012 03:09 PM

Looks all good to me; whether or not MySQL will throw a hissy-fit (I don't think it will)
I don't know; same w/ simply changing a config-setting. But if all else fails you can
always revert back ;}

Just make sure you stop it before you move.

Cedrik 01-30-2012 03:14 PM

You'd better do:

ln -s /www/mysql /var/lib
Both ways work :)

PTrenholme 06-01-2012 12:31 PM

You might want to consider the use of a hard link rather than a soft link. If you're using a Linux file system (like ext, btrfs, etc.) that uses inodes, a hard link to a file increase the "in use" number of the nodes in the file by one. If the "in use" number is greater than zero, the node is not deleted when it's change by writing to the file. Instead, a new free (i.e., node with a zero "in use" number) is used. The "in use" number will not decrease to zero until the the hard link is deleted.

Thus a hard link to a file creates, essentially, a "snapshot" of the file. This minimizes the amount of disk space used by the backup, since only the changed nodes need actual disk space. That's unlike a copy that uses a new node for every node in the base file.

This, by the way, is how it's possible to write to a file (like, e.g., a system file) that's being used by a running Linus system, since the kernel, in essence, hard links opened files, and uses the "virtual hard link" when it references the file, releasing it when the file is closed.

chrism01 06-03-2012 07:07 PM

The OP appears to want to move to a new partition; hard links can only exist in one partition as each partition has its own inode list (ie same ids as any other partition).
IOW, you can symlink across partitions, but not hard link.

PTrenholme 06-04-2012 02:09 PM

Oops! :redface: I meant to post that to a different thread where that OP was asking about writing into a file, but was afraid that he might get it "wrong." (And I found the wrong thread when I looked for it after I woke up the next day with the realization that the hard link might be a good solution for that OP.)

All times are GMT -5. The time now is 09:30 AM.