0

I need to move recursively all the files from one drive to another and the same path/name files rename if different the older by appending to the file name the modification time. Same path/name files overwrite. The sizes of the files vary between 5K to 500M.

Here is a tree of the testing environment I have created and some comments:

/bmrlbackup/drive1/
`-- user001
    `-- directory1
        `-- project001
            |-- file000           #identical
            |-- file001           #older same name
            |-- file0011          #unique
            |-- phase1
            |   |-- file000       #identical
            |   |-- file110       #unique
            |   |-- file999       #newer same name
            |   `-- phase11
            |       `-- file111   #unique
            `-- phase2
                `-- file120       #unique
/bmrlbackup/drive2/
`-- user002
    `-- directory2
        `-- project001
            |-- file000           #identical
            |-- file001           #newer same name
            |-- file0012          #unique
            |-- phase1
            |   |-- file000       #identical
            |   |-- file210       #unique
            |   `-- file999       #older same name
            `-- phase2
                |-- file220       #unique
                `-- phase21
                    `-- file221   #unique

The output for the rsync to move the unique files:

#rsync -a --ignore-existing --remove-source-files $sd1/ $dd1/
project001/
project001/file0011
project001/phase1/
project001/phase1/file110
project001/phase1/phase11/
project001/phase1/phase11/file111
project001/phase2/
project001/phase2/file120

The remaining files to be moved:

#remm="ls -1 $(find $sd1/ -type f)"
/bmrlbackup/drive1/user001/directory1/project001/file000
/bmrlbackup/drive1/user001/directory1/project001/file001
/bmrlbackup/drive1/user001/directory1/project001/phase1/file000
/bmrlbackup/drive1/user001/directory1/project001/phase1/file999

Here, there are files which are the same in both locations and need to be moved and overwrite the destination:

/bmrlbackup/drive1/user001/directory1/project001/file000 
/bmrlbackup/drive1/user001/directory1/project001/phase1/file000

And here there are files which have the same name but different content:

/bmrlbackup/drive1/user001/directory1/project001/file001
/bmrlbackup/drive1/user001/directory1/project001/phase1/file999

The "same name different content" files need to be compared and the older one needs to be moved renamed appended with the modification date&time, so if source is newer then append the name of destination file and move the source, and if the source is older, then append the name of the source and move the name appended source.

The resultant of this process will eventually move all the files from drive1 to drive2.

Please, please, please HELP !!!

0

You can use "diff" to compare FILES line by line. also look at this post find mtime. Then you can use the mv command to move the older file

  • find mtime implies a known range of time, and this is not the case. – fptstl Jan 12 '17 at 23:47
  • How about : if [ −n "$(find file1 −prune −newer file2)" ]; then printf %s\\n "file1 is newer than file2" fi I found this at the find man – Talal Jan 13 '17 at 0:00
0

Use rsync with --update and --backup in both directions:

-u, --update                skip files that are newer on the receiver
-b, --backup                make backups (see --suffix & --backup-dir)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.