Implement a shell script for folder Synchronization

Source: Internet
Author: User

Implement a shell script for folder Synchronization
Algorithm:

 

1. First find/pathname-print> filea # Get the full names of all files in the two folders. <Br/> 2. Compare files. Delete unnecessary files in the folder to be synchronized. Then obtain the full names of all files in the folder to be synchronized. <Br/> 3. Compare files and CP the files added to the source folder to be synchronized. <Br/>

 

This script is used to synchronize all the files in the/share directory and needs to be backed up to/mnt/D/share.

 

#! /Bin/bash </P> <p> Mount/dev/hda6/mnt/D 2>/dev/NULL; unalias rm cp <br/> RM/share/C/APP/* o/share/C/tmp/* o/share/C/APP/* Core/share/C/ TMP/* Core/share/C/APP/. out/share/C/tmp/. out <br/> Find/share-print>/tmp /. share _ # Save the full name of all/share files to/tmp /. share _ </P> <p> Find/mnt/D/share-print | SED's // MNT // D // G'>/tmp /. D _ <br/> chmod 700/tmp /. share _/tmp /. D _ <br/> COUNT = 0 <br/> for I in $ (Comm-23/tmp /. D _/T MP/. Share _); do # compare the differences between/tmp. D _ and/tmp./share _ in the two files. </P> <p> echo "/mnt/d $ I" <br/> RM "/mnt/d $ I"; Count = $ (count + 1 )) # Delete unnecessary files and counts in/mnt/D/share. </P> <p> done # For command; do command; the cycle of done ends here. </P> <p> echo "del $ count file at/mnt/D/share/" <br/> Find/mnt/D/share-print | SED's/ // MNT // D // G'>/tmp /. D _; Count = 0 # obtain the full name of the file again. Initialize the counter. </P> <p> for I in $ (Comm-23/tmp /. share _/tmp /. D _); DO <br/> echo $ I <br/> CP $ I "/mnt/d $ I"; Count = $ (count + 1 )) # Back up the newly added files in/share to/mnt/D/share and count them at the same time. </P> <p> done <br/> echo "already copied $ count file from/share to/mnt/D/share "; sync <br/> umount/mnt/D 2>/dev/null <br/> echo done </P> <p>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.