I'm trying to copy the latest files and directories from one location to another. I'm using the find command with a reference file. Any files newer than the reference file get copied.
find /root/test/BACKUP/ -newer /root/test/BACKUP//reference -exec cp -r '{}' /root/test/backup_170213_0328 ';'
The issue is if the /root/test/BACKUP/ has an sub directories these get copied separately in addition to getting copied as a sub directory. This creates duplicate files in the destination.
[root@localhost S3_Backup]# tree /root/test/BACKUP/
/root/test/BACKUP/
├── Chrysanthemum.jpg
├── Desert.jpg
├── Hydrangeas.jpg
├── Jellyfish.jpg
├── level2
│ ├── Lighthouse.jpg
│ ├── Penguins.jpg
│ ├── teddy.jpg
│ └── Tulips.jpg
└── reference
1 directory, 9 files
[root@localhost S3_Backup]# tree /root/test/backup_170213_0328
/root/test/backup_170213_0328
├── BACKUP
│ ├── Chrysanthemum.jpg
│ ├── Desert.jpg
│ ├── Hydrangeas.jpg
│ ├── Jellyfish.jpg
│ ├── level2
│ │ ├── Lighthouse.jpg
│ │ ├── Penguins.jpg
│ │ ├── teddy.jpg
│ │ └── Tulips.jpg
│ └── reference
└── level2
├── Lighthouse.jpg
├── Penguins.jpg
├── teddy.jpg
└── Tulips.jpg
3 directories, 13 files