February 12th, 2011, 06:24 PM
Using cp to synchronize a backup directory with its source
I have a shell script that contains this code:
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.
cp -R -p lists/* lists.bak
How can I tell UNIX to delete from the copy any files that I have deleted from the source since the last backup?
Last edited by doctormelodious; February 12th, 2011 at 06:36 PM.
February 12th, 2011, 07:04 PM
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.
February 13th, 2011, 06:17 AM
Originally Posted by requinix