Welcome to the Linux Foundation Forum!

How to copy groups of files at once?

Hi,

I've been working on this all morning and I cannot figure it out.

I'm running Ubuntu Server 8.04.4 and I have directories on an ext3 partition (SOURCE) that I would like to copy. I have a USB drive (DESTINATION) connected to the server and mounted NTFS.

#1

I want to copy files from the SOURCE with "preserve" or "-p." I am interested in keeping the timestamps, owner, permissions, etc. Is this just not possible or am I missing something?

#2

I want to give the copy command through BASH and not copy duplicates. If the server asks whether to overwrite/replace, I want the default answer to just be "no." I do not want to sit at the computer for days attending to this copy typing no. Researching all morning, I thought I was golden with the "--reply=no" argument. I then found that this argument was deprecated and did not work (oh, the joy).

On testing, my workaround command was

yes "no" | cp -r /SOURCE/ /DESTINATION/

This worked to preserve the timestamp on the directory. However, it re-copied the (already existing) files in the directory with today's timestamp. This makes the job much longer than it needs to be and messes up the timestamp.

To summarize, I want to copy only directories/files that are not already at the (NTFS) destination and preserve the timestamps, etc. with the directories/files that are copied. I already have a large number of other files on this USB drive for another project so I can't just reformat to, say, ext3 (although it seems that might be easiest at this point) Can this be done? Thanks.

Mark

Comments

  • mfillpot
    mfillpot Posts: 2,177
    If you mean to use this for backup then I recommend using rsync to run the backup mechanisn because rather than always trying to replace each files, it only updates with mising or updated files. A good guide was written at http://www.linux.com/news/enterprise/storage/8200-back-up-like-an-expert-with-rsync.

    If you still want to use the cp command then "cp -a -u" should work, read the manual (http://unixhelp.ed.ac.uk/CGI/man-cgi?cp) to see exactly what they do.

    Now for the real issue, your attempt to copy the files including all attributes will fail because the permissions cannot be retained when you are copying from a unix type file-system (ext3) to a windows filesystem (ntfs) because the windows filesystem permissions are different.
  • gomer
    gomer Posts: 158
    In addition to rsync, you may also want to consider cpio in copy-pass mode. Both tools are generally faster than cp and can preserve all the attributes you want to preserve (assuming destination file system compatibility).

    find /path/to/old/dir -depth -print | cpio -pamd /path/to/new/dir

    -p is copy-pass mode
    -a preserve file's access time
    -m preserve file's modification time
    -d create directories as needed

Categories

Upcoming Training