[TriLUG] Moving /home and others to new partitions

Scott G. Hall ScottGHall at BellSouth.Net
Tue Jan 18 13:50:39 EST 2005


On 01/18/2005 10:44 AM EST, Steve Litt <slitt at troubleshooters.com> wrote:
> On Tuesday 18 January 2005 10:24 am, Rick DeNatale wrote:
> 
> [clip]
> 
>> What's the best way to accomplish this safely?   I know that I need to
>> create a partition for each of these, temporarily mount it, cp the
>> files, test the copy, delete the files from the original location and
>> then remount to the (now empty) original directory.
>>
>> so as an example I'm thinking to move the /public directory
>>
>> 1) Fdisk to create partitions and make filesystems
>> 2) sudo mount /dev/hdcx /mnt/temp
>> 3) Stop samba, atalk, cron services
>> 4) sudo cp -al /public /mnt/temp
>> 5) test somehow that the copy worked. Suggestions?
>> 6) sudo rm -Rf /public/*
>> 7) restart services
> 
> Without addressing any of your other questions, I'd like to give some
> advice on the copy. Most people accomplish this type of tree copy not
> with the cp -R command, but with either tar or cpio. The reason is that
> these archiving utilities really do a good job with ownership,
> permissions, timestamps, hardlinks and symlinks.
> 
> The following script is my cptree command, that copies a tree from one
> place to another. I've used it in my backups for years, and as far as I
> can tell it works perfectly. Mine uses tar, but you can do something
> similar with cpio. 
> 
> #=========== Start of script, delete this line ===============
> #!/bin/bash
> echo Tree copying $1 to $2
> sleep 2
> tar -cvf - $1 | tar --atime-preserve -C $2  -xf -
> #=========== End of script, delete this line ===============

I have something similar in my toolbox:

    #!/bin/sh
    if [ -d "$1" && -r "$1" ]; then
    if [ -d "$2" && -w "$2" ]; then
       cd $1
       find . -print -depth |cpio -pdumanV $2
       exit 0
    else
       echo "Writable destination directory not specified"
    fi
    else
       echo "Readable source directory not specified"
    fi
    echo "USAGE: $0 _location_of_old_directory_ _location_of_new_directory_"
    echo "   or"
    echo "       $0 _location_of_old_directory_ _mountpoint_of_new_partition_"
    exit 1

    - the "-depth" find flag causes directories to be listed after their
      files, upon which the "-ma" cpio flags reset the permission and
      access times of the directories after the files are copied in it

    - I prefer _cpio_ over _tar_ for this, but either way, just make sure
      to set to copy links, not follow them, and to copy special files
      such as devices and FIFO's and such

-- 
Scott G. Hall
Raleigh, NC, USA
ScottGHall at BellSouth.Net



More information about the TriLUG mailing list