Setting user's home folders as data sets

GJSchaller

Contributor
Joined
Feb 10, 2021
Messages
100
I've had my NAS up and running for a while, and am happy with it. So far, so good.

While checking backups today, it occurred to me that the "home" folder is a single data set, and individual user's home folders under it are not separate data sets. If something happens and I need to recover one user's folder from a snapshot, I'll also "recover" everyone else's home folders, too.

Is there a graceful way to convert a user's home folder to a data set? I see discussion on how to turn a folder into a data set by renaming it and moving the contents, but I get the feeling it may not be that easy when a user's home folder is involved.

Thank you!
 
Joined
Oct 22, 2019
Messages
3,641
Create a (temporary) recursive snapshot for your entire pool before proceeding. It will not take up any additional space, and you can destroy the snapshot after you're done.


I see discussion on how to turn a folder into a data set by renaming it and moving the contents, but I get the feeling it may not be that easy when a user's home folder is involved.
If you do it while logged in as "root" (and there are no services or jails accessing the users' home folders), you should be able to do it safely.

The procedure would be to temporarily rename the folders (i.e, each user's home folder).

Something like this:
Code:
/mnt/mypool/homes/brad-old
/mnt/mypool/homes/sarah-old
/mnt/mypool/homes/david-old
/mnt/mypool/homes/rachael-old


Then you can safely create new datasets without worrying about "overlapping" the existing folders.


The new datasets would be created under the "homes" dataset, and named as:
Code:
brad
sarah
david
rachael


Which will automatically set these new dataset mountpoints to:
Code:
/mnt/mypool/homes/brad
/mnt/mypool/homes/sarah
/mnt/mypool/homes/david
/mnt/mypool/homes/rachael


Make sure to assign their ownership and permissions accordingly.


And finally, while still "root", you can use rsync to copy each user's "old" home into their new homes, while preserving ownership and permissions, using the -a ("archive") flag.
Code:
rsync -nva --progress /mnt/mypool/homes/brad-old/ /mnt/mypool/homes/brad/


(The trailing "slashes" are very important.)

If everything looks good, you can remove the -n flag, and run it again to actually copy the data over.

If everything works properly, you can delete the old homes.
 
Last edited:

GJSchaller

Contributor
Joined
Feb 10, 2021
Messages
100
I wrote the commands up in a Google Sheet so I wouldn't fatfinger them while trying this, and for a sanity check. Does this look correct? (I made a temporary data set /mnt/data/homes-old to hold the existing data, so I could just whack that dataset when done)

Code:
mv /mnt/data/geoffrey /mnt/data/homes-old/geoffrey
mv /mnt/data/diane /mnt/data/homes-old/diane
mv /mnt/data/patricia /mnt/data/homes-old/patricia
mv /mnt/data/sylvia /mnt/data/homes-old/sylvia

zfs create data/home/geoffrey
zfs create data/home/diane
zfs create data/home/patricia
zfs create data/home/sylvia

chown geoffrey geoffrey
chown diane diane
chown patricia patricia
chown sylvia sylvia

chgrp geoffrey geoffrey
chgrp diane diane
chgrp patricia patricia
chgrp sylvia sylvia

chmod 755 geoffrey
chmod 755 diane
chmod 755 patricia
chmod 755 sylvia

rsync -nva --progress /mnt/data/homes-old/geoffrey/ /mnt/data/home/geoffrey/
rsync -nva --progress /mnt/data/homes-old/diane/ /mnt/data/home/diane/
rsync -nva --progress /mnt/data/homes-old/patricia/ /mnt/data/home/patricia/
rsync -nva --progress /mnt/data/homes-old/sylvia/ /mnt/data/home/sylvia/
 
Last edited:
Joined
Oct 22, 2019
Messages
3,641
Sorry, was busy.

I would create ("mkdir") the "homes-old" directory before the "mv" commands. ("homes-old" is only a temporary placeholder.)

I would create the datasets in the GUI; not in the command-line. (You should create the "data/home" dataset first, and then all the children underneath.)

I would assign the ownership and permissions for the new datasets in the GUI; not in the command-line. (You can check the "recursive" option, "Apply User", and "Apply Group", as well as choose the permissions. The recursive option won't make much difference, since it's a brand new dataset. The rsync command should preserve your original permissions and ownerships.)

The rsync commands look good. Don't forget to remove the "-n" flag when you want to do it for real.

Now you can start your services and jails, and allow the users to login again.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Or, you could forget all this messing around and just recognize that the .zfs directory presents you the snapshots view of the filesystem... allowing you to copy back one single user's directory at any time you want from a snapshot.
 
Top