Find the answer to your Linux question:
Results 1 to 8 of 8
I use the command cp -u ... to copy from one place to another (e.g. to a backup device), but only files that are new to the target directory. For ...
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    21

    cp -r -u ?

    I use the command
    cp -u ...
    to copy from one place to another (e.g. to a backup device), but only
    files that are new to the target directory. For large directories with large
    files, this avoids long transfers. However, when I copy not only files but
    directories with files, as in
    cp -r -u ...
    this seems not to work; it then takes the time it takes to copy everything,
    new and old. Does the -r override the -u, and if so, why?

  2. #2
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    623
    Seems that it does, you'd have to read the source code to see why.

    Consider using rsync instead. It using a "sliding window checksum" algorithm, and not only transfers only the files that have changed, it transfers only the changed blocks of those.

  3. #3
    Just Joined!
    Join Date
    Dec 2010
    Posts
    21
    Thanks! I was not aware of that command. Makes me wonder how many
    other commands there might be that I could use...

  4. #4
    Just Joined!
    Join Date
    Mar 2008
    Posts
    28
    dieterhansbritz, try these rysnc commands.

    Rysnc with resume:
    rsync -r --partial --progress --append --rsh=ssh /media/mounteddrive /media/mounteddrivebackup

    Rysnc with resume, delete empty directories and extra files and directories that no longer exist from the source that currently exists on the destination.
    rsync -r --partial --progress --append --prune-empty-dirs --delete

  5. #5
    Just Joined!
    Join Date
    Dec 2010
    Posts
    1
    I have this in my backup script:

    cp -v --update -p -r $1/* $2

    and it does exactly what you (and I) want. I would suggest you look for some other reason why it isn't working.

    Don

  6. #6
    Linux Newbie unlimitedscolobb's Avatar
    Join Date
    Jan 2008
    Posts
    120
    Quote Originally Posted by dieterhansbritz View Post
    cp -r -u ...
    this seems not to work; it then takes the time it takes to copy everything,
    new and old. Does the -r override the -u, and if so, why?
    Just throwing in a wild guess. Sorry, no time to look through the source now

    May it be so that cp checks not only files, but also directories when run with -u? In that case, if you create a new file in a directory, it will copy the entire directory, because the modification time of the entire directory has changed.

    rsync should cope better with the problem, though

  7. #7
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    623
    Quote Originally Posted by lindylex View Post
    dieterhansbritz, try these rysnc commands.

    Rysnc with resume:
    rsync -r --partial --progress --append --rsh=ssh /media/mounteddrive /media/mounteddrivebackup
    Why specify a remote shell on a local-to-local copy?

  8. #8
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    623
    Quote Originally Posted by unlimitedscolobb View Post
    Just throwing in a wild guess. Sorry, no time to look through the source now

    May it be so that cp checks not only files, but also directories when run with -u? In that case, if you create a new file in a directory, it will copy the entire directory, because the modification time of the entire directory has changed.

    rsync should cope better with the problem, though
    Intuitively that sounds exactly right. I have time to look through the source, I'm just too lazy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...