1

I have a NAS box running in JBOD mode (two physical disks that act as one). Unfortunately I've had no end of problems with this configuration and wish to change it to two seperate disks. However all my files are spread between the two disks and I'd like to consolodate them onto one drive before proceeding.

I have a file structure like this (same on both drives) but there should be no file confilcts (files should only exist on one drive).

/mnt/disk1/home/
 |-- a
 |   |-- file1.txt
 |   |-- file2.txt
 |   |-- file3.txt
 |   |-- file4.txt
 |-- b
 |   |-- file5.txt
 |   |-- file6.txt
 |   `-- file7.txt
 `-- c
     |-- file8.txt
     |-- file9.txt
     `-- file10.txt

/mnt/disk2/home/
 |-- a
 |   |-- file11.txt
 |   |-- file12.txt
 |   |-- file13.txt
 |   `-- file14.txt
 |-- b
 |   |-- file15.txt
 |   |-- file16.txt
 |   `-- file17.txt
 `-- c
     |-- file18.txt
     |-- file19.txt
     `-- file20.txt

How can I merge the files from one disk onto the other (either copy OR move - it doesn't matter, the disk being copied FROM is going to be formatted afterwards anyway).

I've tried variations of rsync, mv, cp etc but not finding the correct arguments to use. I've seen this question (Merge 2 directory trees in Linux without copying?) but this specifies that the files SHOULDN'T be copied. I'm looking for the opposite (specify that files need to be copied).

-Thanks

3

Just use a tarpipe to consolidate them:

( cd /mnt/disk2/home && tar cf - . ) | ( cd /mnt/disk1/home && tar xf - )

This will move all of the files and subdirs from /mnt/disk2/home to /mnt/disk1/home. The result will be:

/mnt/disk1/home/
 |-- a
 |   |-- file1.txt
 |   |-- file2.txt
 |   |-- file3.txt
 |   |-- file4.txt
 |   |-- file11.txt
 |   |-- file12.txt
 |   |-- file13.txt
 |   `-- file14.txt
 |-- b
 |   |-- file5.txt
 |   |-- file6.txt
 |   |-- file7.txt
 |   |-- file15.txt
 |   |-- file16.txt
 |   |-- file17.txt
 `-- c
     |-- file8.txt
     |-- file9.txt
     |-- file10.txt
     |-- file18.txt
     |-- file19.txt
     `-- file20.txt
| improve this answer | |
  • Thank for the reply. Does this tar all my files, then move the tarball, then untar them? If so I assume I will need the same amount (or close) of free filespace available on the first disk as the size of the files I'm copying - and also the same situation on the second disk (space for the tarball and the files being untarred)?? – calumbrodie Mar 26 '11 at 23:40
  • 1
    @calumbrodie: No tarball is created. All data is transferred from source to destination through the pipe, without using any additional disk storage. (Personally, I would use rsync, but this should work just as well. +1.) – Steven Monday Mar 26 '11 at 23:54
  • When I try to use the syntax provided I get the following error... 'Cowardly refusing to create an empty archive' – calumbrodie Mar 27 '11 at 12:25
  • I forgot the . in the first tar command. – toppledwagon Mar 27 '11 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.