[Techtalk] Copying complete directories

Mary mary-linuxchix at puzzling.org
Thu Mar 25 11:57:05 EST 2004


On Wed, Mar 24, 2004, Lucky Lady wrote:
> I have just set up a Linux (RH 8) server to (hopefully) replace our
> current backup server. 
> 
> What I need to be able to do is copy entire directories and their
> contents from the old server to the new one. FTP and SSH are not an
> option. 
> 
> Is there an easy way for me to do this?

Why aren't FTP and SSH an option? Do you not have them installed? Do you
not have networking set up? It's a bit hard to eliminate options based
on what you've said. If you can't or won't set up networking, you need
to get both drives in the same machine. If you can set up networking, is
there a reason why you can't use SSH or FTP? If we know the reason, then
we can figure out options that avoid the issue.

I can see a few ways:

Networked option: rsync

Not networked option: put old machine's drive in new machine. Mount old
machine's drive. Copy files from old drive to new. The normal way to do
this is (PLEASE check this command on a test directory before using it):

cd [location]
tar cf - [files] | tar xf - -C [target]

replace "[location]" with your original location, "[files]" with a list
of files or directories you wish to copy, and "[target]" with the new
location.

The command works like this:

tar         the archiving command

c           create an archive

f           in the following file

-           output the archive to standard output -- normally a file name
            would go here, this is a special case
            
[files]     the filenames or directories to archive

|           redirect standard output to the standard input of the next
            command
            
tar         the same archiving command

x           extract an archive

f           from the following file

-           take the archive from standard input (again, this is a special
            case, normally the archive would be a real file name)
            
-C          output into the following directory

[target]    the directory to output into


The "cp" command also has some options to do copies of directories (-r)
with all permissions preserved (-a).
-Mary


More information about the Techtalk mailing list