LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   How copy older backup files into new folder witout losing new additional files (https://www.linuxquestions.org/questions/linux-server-73/how-copy-older-backup-files-into-new-folder-witout-losing-new-additional-files-4175552524/)

thm 09-03-2015 11:05 AM

How copy older backup files into new folder witout losing new additional files
 
I have a backup folder with differen subfolder and a lot of files and an newer folder with subfolder and files. The new folder has some additonal files, which don't want lose by copying the old folder back. Some files in the old and the new folder have the same name but they have different sizes.
I want to copy the old file variant into the new folder, but not lose the additonal new files. With which command is this possible?

rtmistler 09-03-2015 01:14 PM

So you want to copy the old directory to the newer one? If you use cp -r it will recurse through subdirectories and absent the -n (noclobber) option, then those old file copies will overwrite the newer copies that it sounds like you wanted to replace. Either case, non-overlapping files, such as pre-existing ones in the destination directory will be left alone.

Am I understanding correctly what you want to do?

thm 09-04-2015 01:13 AM

Thanks a lot for your answer.
Yes, I want to copy the oder directory to the newer one. But I want replace only the overlapping files, the additional, non-overlapping files in the newer directory shouldn't be touched.
For this case the command line cp -r -n would work?

Beryllos 09-04-2015 04:32 PM

No, the command to copy all and overwrite existing files in the destination directory is just cp -r with the appropriate source and destination specifiers.

By the way, if you need to copy the contents of a directory, not the directory itself, you will need to correctly specify the source, or it may copy the source directory into the destination directory (creating the copies as a subdirectory). One method to avoid this mistake is to cd into the backup directory and then cp the contents, for example:
Code:

cd /my_backups/backup_directory
cp -r * /home/thm/destination_directory

Alternatively you could cp the directory and append /* when specifying the source:
Code:

cp -r /my_backups/backup_directory/* /home/thm/destination_directory


All times are GMT -5. The time now is 10:58 AM.