- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- remote file copy from multiple directories
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2007 09:14 PM
03-19-2007 09:14 PM
I am experiencing a mental block on this one and I need your help.
I want to schedule a job on cron that will copy files from multiple directories daily from a remote system. With each day I want to copy only new files from the remote directories. The remote host where the files are follows the following parttern
/BTC/Dir1/tertiary/*
/BTC/Dir2/tretiary/*
/BTC/Dir3/tertiary/*
and so on.
Where do I start such that I can create a loop to copy daily from the remote system to local using cron?
Thx
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2007 09:23 PM
03-19-2007 09:23 PM
Re: remote file copy from multiple directories
- JarleB
- Tags:
- rsync
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2007 09:26 PM
03-19-2007 09:26 PM
Re: remote file copy from multiple directories
I would start by looking at this earlier thread:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1109365
If you insists on ftp:
You would ftp to the machine and then use the cd command to change directories.
Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
So far you have rewarded 7 of 113 answers !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2007 09:28 PM
03-19-2007 09:28 PM
Re: remote file copy from multiple directories
- Tags:
- NFS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2007 09:29 PM
03-19-2007 09:29 PM
Re: remote file copy from multiple directories
Please kindly guide me with sample text that I can customise?
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2007 09:36 PM
03-19-2007 09:36 PM
Re: remote file copy from multiple directories
The 2 systems are standalones on the same network. I could NFS mount the remote filesystem onto the local host. Then I will need to copy the files to the local machine so that I can manipulate them with changing the source.
I know how to NFS mount, how do I then move forward so that I can have a cron that copies the files to a local directory?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2007 09:39 PM
03-19-2007 09:39 PM
Re: remote file copy from multiple directories
We need to know how you are going to access the files. If NFS, it is easy. If pushing by ftp, still easy. If pulling over ftp, and you can't remove the files you copied, you are hosed and must turn to advanced AI technology. You must copy all files and then remove the dups. Or you must parse the name/size/timestamp and see if you already have done it. And if not, you must ftp-get the file.
As JarleB says, if you have to use ftp, you should look at rsync instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2007 09:48 PM
03-19-2007 09:48 PM
Re: remote file copy from multiple directories
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2007 10:05 PM
03-19-2007 10:05 PM
Re: remote file copy from multiple directories
This is good. You should look at my solution in Peter's link above. Then replace the "ftp" plugin by a cp.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2007 10:35 PM
03-19-2007 10:35 PM
Re: remote file copy from multiple directories
/BTC/Dir1/tertiary/*
/BTC/Dir2/tretiary/*
/BTC/Dir3/tertiary/*
/Btc/Dir4/tertiary/*
Please kindly assist with sample syntax?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2007 11:23 PM
03-19-2007 11:23 PM
Re: remote file copy from multiple directories
will there be different local directories
Dir1/
Dir2/
...
as well or differs the local from the remote structure?
If it is equivalent, adapt+try the following code fragment. It will coy file not already local - you can change this condition to your needs:
nfsdir=/nfsmount/remhost/BTC
locdir=/archive/btc
inter=tertiary
for dir in Dir1 Dir2 ...
do
[ -d $locdir/$dir/$inter ] || mkdir $locdir/$dir/$inter
for f in $nfsdir/$dir/$inter/*
do
[ -f $locdir/$dir/$inter/${f##*/} ] && continue
cp -p $f $locdir/$dir/$inter
done
done
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2007 12:02 AM
03-20-2007 12:02 AM
Re: remote file copy from multiple directories
Where do i stick somethin like this:
for i in `find . -mtime 1 -print |xargs ls -l | awk '{print $9}''
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2007 12:13 AM
03-20-2007 12:13 AM
Re: remote file copy from multiple directories
Correct the logic here?
We are going to mount the remote filesystem onto the local host thru NFS.
We do a copy from the NFS filesystem sub-directories to a seperate but 1 directory on the local host.
The copy should only copy files from last nite. Example if today is the 20th the copy should get files for the 19th.
How do we place the above into a script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2007 01:13 AM
03-20-2007 01:13 AM
Re: remote file copy from multiple directories
The "for" loop below is what I tried to use but it is limited to
/BTC/DataMediation/L1/tertiary/
/BTC/DataMediation/L2/tertiary/
/BTC/DataMediation/L3/tertiary/
/BTC/DataMediation/L4/tertiary/
It copies from the various L1,L2,L3 directories files that are a day old. To another filesystem /backup/Transfer.
I wanted to expand the logic above into a loop such that I can copy from other subdirectories in the same manner. Eg
/BTC/DataMediation/G1/tertiary/
/BTC/DataMediation/G2/tertiary/
/BTC/DataMediation/G3/tertiary/
To do this I need a to create a loop, that where I got stuck?
Please Help
SAMPLE SYNTAX:
For i in
'find /BTC_DataMediation/L*/tertiary/ -mtime 1 -print|xargs ls -l|awk '{print $9}''
do
cp -p $i /backup/Transfer/
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2007 02:58 AM
03-20-2007 02:58 AM
Solutionthere where many threads in this forum dealing with timebased selection of files - nevertheless:
I suggest to take the newest local file as a reference for the decision to copy-or-not - though can can modify this to a solition using a file created by 'touch
If you copy all remote files, found in different directories, to a single directory, there is the possiblity, that the plain filenames are not unique and one file is overwriting the other. Your scenario may not have this inpact, however.
nfsdir=/nfsmount/remhost/BTC
locdir=/archive/btc
inter=tertiary
touch nowfile
newest_got=$(ls -t $locdir | sed 1q)
for dir in Dir1 Dir2 ...
do
for f in $nfsdir/$dir/$inter/*
do
if [ -n "$newest_got" ]
then
[ $f -ot $locdir/$newest_got ] && continue
fi
[ $f -nt nowfile ] && continue
cp -p $f $locdir
done
done
rm nowfile
mfG Peter
PS: Your profile states:
"I have assigned points to 7 of 117 responses to my questions."
You really should change that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2007 03:35 PM - edited 10-09-2011 08:36 PM
03-20-2007 03:35 PM - edited 10-09-2011 08:36 PM
Re: remote file copy from multiple directories
>for i in `find . -mtime 1 -print |xargs ls -l | awk '{print $9}''
Did you see my solution regarding a reference file?
If you want to use find, no need to do for, xargs or ls. You should do:
find /BTC_DataMediation/L*/tertiary/ -mtime 1 -print | while read file; do
cp -p $file /backup/Transfer/
done
If you know you aren't finding "lots" of files, then you can use:
for file in $(find ... ); do
cp -p $file /backup/Transfer/
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2007 06:00 PM
03-20-2007 06:00 PM
Re: remote file copy from multiple directories
I see the logic in your script, I'll test it and give the results. The files will not overwrite because they are all unique.
Meanwhile the other suggested solution are much appreciated but they do not give me a copying solution based on time.
The reason why it's time based is that I don't want to copy everything from the remote directory that was already copied.
Thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2007 06:17 PM
03-20-2007 06:17 PM
Re: remote file copy from multiple directories
My script in the following link can be changed to be based on time:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1109365
You just need to use what Peter has here:
[ $f -nt nowfile ]
to sort the result of find of the timestamps on the original machine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2007 08:53 PM
03-20-2007 08:53 PM
Re: remote file copy from multiple directories
Your script does work I think just one tweek will make it work 100%.
Please look at the files below at the source:
-rw-rw-r-- 1 root other 54192 Mar 21 01:17 L1.TTFILE00.1727.gz
-rw-rw-r-- 1 root other 51900 Mar 21 01:28 L1.TTFILE02.1725.gz
-rw-rw-r-- 1 root other 20139 Mar 21 03:13 L1.TTFILE00.1728.gz
-rw-rw-r-- 1 root other 17793 Mar 21 03:24 L1.TTFILE02.1726.gz
-rw-rw-r-- 1 root other 75776 Mar 21 05:11 L1.TTFILE00.1729
-rw-rw-r-- 1 root other 69632 Mar 21 05:23 L1.TTFILE02.1727
-rw-rw-r-- 1 root other 53248 Mar 21 07:11 L1.TTFILE00.1730
-rw-rw-r-- 1 root other 51200 Mar 21 07:23 L1.TTFILE02.1728
-rw-rw-r-- 1 root other 180224 Mar 21 09:12 L1.TTFILE00.1731
-rw-rw-r-- 1 root other 196608 Mar 21 09:23 L1.TTFILE02.1729
-rw-rw-r-- 1 root other 299008 Mar 21 2007 L1.TTFILE00.1732
-rw-rw-r-- 1 root other 323584 Mar 21 2007 L1.TTFILE02.1730
-rw-rw-r-- 1 root other 1464320 Mar 21 2007 L1.TTFILE00.1733
-rw-rw-r-- 1 root other 1536000 Mar 21 2007 L1.TTFILE02.1731
Wed Mar 21 09:59:36 SAST 2007
Script Output:
-rw-rw-r-- 1 root other 180224 Mar 21 09:12 /nfscdm/L1/tertiary/L1.TTFILE00.1731
-rw-rw-r-- 1 root other 196608 Mar 21 09:23 /nfscdm/L1/tertiary/L1.TTFILE02.1729
-rw-rw-r-- 1 root other 18432 Mar 21 08:30 /nfscdm/L2/tertiary/L2.TTFILE00.1576
-rw-rw-r-- 1 root other 20480 Mar 21 08:31 /nfscdm/L2/tertiary/L2.TTFILE02.1575
Looking at the above you will notice that the output files from the script have the right date but they are fewer than the files at the source. Therefore not all files are copied. I think the "touch nowfile" line in the script has something to do with this. Is it ok to assume that if the script ran at an ealiear time before 0900Hrs like I did, I will get all files?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2007 09:58 PM
03-20-2007 09:58 PM
Re: remote file copy from multiple directories
the statement
touch nowfile
will set a mark at the start of the script, that no files modified AFTER the start will be considered as copy candidates.
So the possibility is lowered (but is not zero) that you copy incomplete files. These skipped files will be copied at the next run of the script.
But look carefully at the difference of this lines:
-rw-rw-r-- 1 root other 196608 Mar 21 09:23 L1.TTFILE02.1729
-rw-rw-r-- 1 root other 299008 Mar 21 2007 L1.TTFILE00.1732
It seems to me be, that the system clocks of your local host and the NFS server differ and so the comparing of timestamp seems incorrect:
The output format of the second line tells us a timestamp in the future (relativly seen on the local host)!
Keep in mind, that we create the stamp (on file nowfile) on the local filesystem, so no write access over NFS is necessary.
mfG Peter
PS: I really considered NOT to reply to your last question, since you do not honour the work of the answering forum members by giving points:
>>
assigned points to 7 of 120 responses
<<
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2007 10:41 PM
03-20-2007 10:41 PM
Re: remote file copy from multiple directories
I appreciate your help, thax very much. It may seem I don't give points but I once the solution is found. It is not always that you get the right solution from each response.
You can see in the dialogue that your solution is different all the other and it is the one that met all requirements.
Maybe I should also give points for partial solutions and efforts.
PS: The timestamp on both systems is only a few seconds apart but timezone is GMT on 1 and SAST on the other
Thanks Again