0

My install had the /home folder inside /. I wanted to add a separate /home partition, so I created a small backup partition on a different drive, added it to /etc/fstab, and used rsync with -aXS to move my old /home folder to this new partition. I then did a fresh install with a /home partition. Now I would like to move my files back from the old /home folder into the new /home directory. What is the best way to do this?

What I tried: sudo rsync -aXS /home_backup/. /new_home_partition/. as per this guide

This copied the old /home folder itself into the /home partition (i.e. it created /home/home), which is not what I wanted. I figured I could run the same command, but on the subfolders within the backup folder rather than on the folder itself. Is this the best way to go about it?

I saw this similar question, but as I understand it, cp will not preserve information like permissions and links. I also saw this question, but I don't know how to work with tarballs (and I'm not positive the OP's situation is the same). Any help would be appreciated, as I'm by no means an expert!

P.S. What is the best command to remove all files from the fresh /home partition before copying the backup files into it?

Edit: Looks like I was able to resolve this, but I still don't know what happened (added a comment below).

6
  • 1
    Did that rsync command complete? If so, then rename /home to /home2. Then cd /home2/home/; mv * ... Since its all on the same file system, the move will be instantaneous. Don't rsync or cp again. That will take time.
    – Ray
    Aug 30, 2021 at 2:53
  • To clarify, copying files take time. Moving files from one file system to another is like a copy + remove. However, if it's doing a move within the same file system, it's immediate since it's just updating the location of the directory.
    – Ray
    Aug 30, 2021 at 2:54
  • cp will preserve permissions, links - if you tell it to. Me, I'd just copy the files, then run a diff before I rm. Depending on what is there, I may also use rsync, but we've got few details of what number of files are involved (hundreds, thousands, millions etc) nor size of files (MB, GB, TB..) etc so it's to me opinion as to best method. I'd also likely use a live system to perform it; but again I don't have details that would dictate if that's what I'd use...
    – guiverc
    Aug 30, 2021 at 3:01
  • You say that the command created a /home/home folder. So I guess you must have had home folder inside your /home_backup. If this is the case, just use /home_backup/home as a source argument to your rsync command instead of just /home_backup.
    – raj
    Aug 30, 2021 at 10:11
  • I was able to resolve this, but I'm still not sure what happened. When I logged in via liveUSB and mounted the /home partition using fstab, I was able to see all the files I had originally tried to sync into it. However when I logged in as myself, /home was empty. I tried rsync again, and this time it worked. I wish I could call this a learning experience, but I don't know why it worked, and I don't understand how I was able to see files in the partition logged in from a different disk, but not when logged in as myself. Thank you again everyone for your suggestions!!!
    – Jupiter
    Aug 30, 2021 at 18:10

1 Answer 1

0

rsync is an appropriate tool to make an identical copy of a directory structure. To preserve permissions with rsync, use the a option. More complete preservation of original properties is obtained with the options -H, -A and -X (see man rsync to see what they do). These are not included in the -a option for performance reasons. You can add them if needed. For example, if you extensively work with hard links, you will want to add the -H option to keep hard linked items in the source as one file in the destination as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .