Two scripts for setting up the Ubuntu Source

Source: Internet
Author: User
Tags rsync

I recently applied for a general-configuration server from the company for a new Ubuntu source. I also bought a hard disk and the hardware was ready.

Then we installed a Ubuntu 9.04 Server, ssh, Nginx, and a little bit of configuration, and the service was ready. This process was quite simple and smooth, so I won't say much about it.



Next, you can start data synchronization. Because my goal is a complete source, I didn't use tools like apt-mirror, but directly captured upstream data using rsync. This data size is very large, so I would like to try to select the fastest source with rsync, but in the vast Ubuntu official source list, which of the following sources is the fastest? No one will tell you the answer, because everyone's network environment is different. Therefore, the best way to do this is to perform on-site tests. The so-called cutting-edge means that there will be GB of data to be downloaded later. This test is absolutely valuable.

Script (not perfect, enough ):

#! /Bin/bash
Urls = 'curl https://launchpad.net/Ubuntu/+archivemirrors |
Grep-B 2> rsync </a> | grep http | awk-F "{print $2 }'
Rm res
Echo "$ urls" | while read url; do
Rm T
Wget-q -- no-cache-o t "$ url/ls-lR.gz "&
Sleep 3
Kill %
Echo "testing... $ url"
Echo-n "$ url"> res
Ls-l T> res
Done

Sort-k 6-n res> fast_mirror
Rm res T
Finally, you can use tail fast_mirror to view the source with the largest number of bytes downloaded in three seconds. I have a source that can download the ls-lr.gz version 7.4min 3 seconds.
Then, you can first update most of the data from the fastest source. After that, update the data to the official source to ensure the latest data. I use this script:

#! /Bin/bash
[[$ UID = 0] | {echo "Must be root to run this script."; exit 0 ;}
LOCK = "/data/sync_sh/lock"
LOG = "/data/sync_sh/log"

While true; do
Echo-e "start sync @ 'date'" | tee-a $ LOG

If [-f $ LOCK]; then
Echo "another sync is running, I exiting..." | tee-a $ LOG
Exit 1
Fi
Touch $ LOCK

St = 'date + % s'
Rsync -- timeout = 120 -- exclude = ".~ Tmp ~ "-AvP -- delete-excluded -- progress rsync: // archive.ubuntu.com/ubuntu/pool// data/mirrors/ubuntu/pool/
Res = $?
If [$ res-eq 0]; then
Echo "rsync pool succ" | tee-a $ LOG
Et = 'date + % s'
Echo "pool sync use $ ($ et-$ st) sec =$ ($ et-$ st)/60 )): $ ($ et-$ st) % 60) "| tee-a $ LOG
Else
Echo "rsync pool failed" $ res | tee-a $ LOG
Fi

St = 'date + % s'
Rsync -- timeout = 120 -- exclude = ".~ Tmp ~ "-AvP -- delete-excluded -- progress rsync: // archive.Ubuntu.com/ubuntu//data/mirrors/ubuntu/
Res = $?
If [$ res-eq 0]; then
Echo "rsync all succ" | tee-a $ LOG
Et = 'date + % s'
Echo "all sync use $ ($ et-$ st) sec =$ ($ et-$ st)/60 )): $ ($ et-$ st) % 60) "| tee-a $ LOG
Else
Echo "rsync all failed" $ res | tee-a $ LOG
Fi

Df | grep "/data" | tee-a $ LOG
Echo-e "end sync @ 'date'" | tee-a $ LOG

Rm $ LOCK

Sleep 7200
Done
This script updates the pool directory first, and then updates the entire directory to reduce the possibility that a software already exists in the Software List, but cannot be downloaded.
The script is always running. 2 hours after the last update, start the next update. Is this the latest source in China?
PS: thanks to the walkerxk of lupa, the server Master, for enthusiastic help when I set up the source.
 

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.