Hello there,
Am trying to copy all the folders and their content (files) created on yesterday to a remote machine in LAN, without changing the folder structure and name.
The script i build is not working properly..
Can you please guide me to achieve.
Here goes the script which i wrote..
@vijaydsk,
please start using markdown code tags when posting data/code sample. I've edited your OP already.
As there's multiple issues with your sample code, I'd start by "validating" your script at shell check first, fixing the identified issues and go from there.
I think you want -type d -mtime 1
This addresses mtimes >24hours and <48 hours.
Because rsysnc is recursive you can at that point prune the recursion in find: -type d -mtime 1 -prune -exec ...
Can you please let me know what exactly prune does?
And another small help...
If I need to copy files created 120 days, mtime 120 is sufficient? or do I need to change anything?
Thanks in advance.
The -prune skips the recursion into further sub directories.
It should be used if there is already a recursive tool like rsync.
The -type d -mtime 120 examines the date of the directory.
If you want to examine the date of the individual files then it is -type f -mtime 120
and rsync runs on the files so won't do a recursion so there should not be -prune
can turn into an issue. If a day is skipped (machine down, unexpected failure, target file system full), you won't get it back.
Minimum suggestion is to have a default of 120 days, but an option to specify another number. It would also be helpful to log all actions, or to have a reporting script to detect omissions.
My style is to copy all files older than 120 days which do not already have a copy. Rsync should take care of that last part in any case.
Also, -mtime does not select days. It selects intervals of 86400 seconds from the time you run it, so if you run at 11:30:00 you will get files from 11:30:00 on one day to 11:29:59 on the next day. In GNU find, the -daystart option is frequently helpful.
Thanks @Paul_Pedant for the good idea.
Can you help me modifying my code?
My requirement is as follows..
All the directories (with files) to be copied on the an external disk connected into another ubuntu machine and remove from the server.
On average 600 to 700 folders will be created and each folder is having .png files in it.
I need to maintain 120 days data in the server and rest move out to external hdd.
Hello @Neo
Agree.
If you look from the other (my) angle, am asking the experts to modify my code which I wrote with mistakes in my first post.
Hence, I provided my requirement.
Hope am clear in asking.
For me, forums are to share the knowledge and help others to learn and improve.
Expected the same from this community too.
Correct me if am wrong.