#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    122
    Rep Power
    65

    Using cp to synchronize a backup directory with its source


    I have a shell script that contains this code:

    Code:
    cp -R -p lists/* lists.bak
    The script runs, and the directory gets copied. Now, I make changes to one file in the source directory, and I delete another file. Then I run the script again. The changed file gets copied as expected, but the file I deleted from the source is still in the backup.

    How can I tell UNIX to delete from the copy any files that I have deleted from the source since the last backup?

    Thanks,
    DM
    Last edited by doctormelodious; February 12th, 2011 at 05:36 PM.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,007
    Rep Power
    9398
    You can't do it easily. You have to maintain a list of files from the previous copy and compare that against the existing files. Something which cp isn't really good for.

    Try using rsync instead.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    122
    Rep Power
    65
    Thanks!

    Originally Posted by requinix
    You can't do it easily. You have to maintain a list of files from the previous copy and compare that against the existing files. Something which cp isn't really good for.

    Try using rsync instead.

IMN logo majestic logo threadwatch logo seochat tools logo