- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script or commands to sync two folders
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
10-17-2005 01:20 AM
10-17-2005 01:20 AM
We have two folders named dir1 and dir2.
we have files in these two folders.
We have some files in these two folders with same name but different time stamps(It can be same time stamp also). I have to sync between the two directories based on the time stamp of files. ie..recently modified file should overwrite the older one in the other directory.
can you suggest me a solution to this ? I think rsync will work. But again rsync won't do the reverse updation.
Thanks
PVR
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 03:19 AM
10-17-2005 03:19 AM
Re: Script or commands to sync two folders
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 03:45 AM
10-17-2005 03:45 AM
Re: Script or commands to sync two folders
I realize that rsync is meant for remote systems, but I believe that it can handle the same system as an argument twice equally well.
You can find rsync at:
http://hpux.cs.utah.edu/hppd/cgi-bin/search?package=on&description=on&term=rsync&Search=Search
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 07:34 AM
10-17-2005 07:34 AM
Re: Script or commands to sync two folders
Make a third directory, use find and cpio to copy files from dir1 into dir3
Then use find and cpio to copy files from dir2 to dir3 and only allow overwrite of newer files
Then rename dir1 and dir2 to backup names and symbolically link dir1 and dir2 to dir3
That way you can access the files from either the dir1 or dir2 directory but there will only be one file so you have no syncing issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 03:49 PM
10-17-2005 03:49 PM
Re: Script or commands to sync two folders
Chris:- We need this solution for an application.
John:- If I do a rsync from dira to dirb, then we are not syncing based on time stamps. we need to update the old file with new file. I think we may need to write some scripts for this.
Thanks for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 06:02 PM
10-17-2005 06:02 PM
Re: Script or commands to sync two folders
#!/bin/ksh
# User input
dir1="" # input here
dir2="" # input here
for file in `find ${dir1} -type f`
do
sfile=`basename $file`
echo "${file} <- sync -> ${dir2}/${sfile}"
syncfile=$(find ${dir2} -name ${sfile} -newer ${file} -print)
# Sync operation
if [[ ! -z ${syncfile} ]]
then
dstfile=`basename ${syncfile}
cp -fp ${syncfile} ${dir1}/${dstfile}
echo "Sync operation done"
else
cp -fp ${file} ${dir2}/${sfile}
echo "Reverse Sync operation done"
fi
done
# END
exit 0
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2005 02:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2005 10:28 PM
10-18-2005 10:28 PM