]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | #!/usr/bin/env bash |
7c673cae FG |
2 | set -e |
3 | # | |
4 | # Script to mirror Ceph locally | |
5 | # | |
6 | # Please, choose a local source and do not sync in a shorter interval than | |
7 | # 3 hours. | |
8 | # | |
9 | SILENT=0 | |
10 | ||
11 | # All available source mirrors | |
12 | declare -A SOURCES | |
13 | SOURCES[eu]="eu.ceph.com" | |
14 | SOURCES[de]="de.ceph.com" | |
15 | SOURCES[se]="se.ceph.com" | |
7c673cae FG |
16 | SOURCES[au]="au.ceph.com" |
17 | SOURCES[us]="download.ceph.com" | |
7c673cae | 18 | SOURCES[fr]="fr.ceph.com" |
20effc67 | 19 | SOURCES[ca]="ca.ceph.com" |
7c673cae FG |
20 | SOURCES[us-west]="us-west.ceph.com" |
21 | SOURCES[global]="download.ceph.com" | |
22 | ||
23 | function print_usage() { | |
24 | echo "$0 [-q ] -s <source mirror> -t <target directory>" | |
25 | } | |
26 | ||
27 | while getopts ":qhs:t:" opt; do | |
28 | case $opt in | |
29 | q) | |
30 | SILENT=1 | |
31 | ;; | |
32 | s) | |
33 | SOURCE=$OPTARG | |
34 | ;; | |
35 | t) | |
36 | TARGET=$OPTARG | |
37 | ;; | |
38 | h) | |
39 | HELP=1 | |
40 | ;; | |
41 | \?) | |
42 | print_usage | |
43 | exit 1 | |
44 | ;; | |
45 | esac | |
46 | done | |
47 | ||
48 | if [ ! -z "$HELP" ] || [ -z "$TARGET" ] || [ -z "$SOURCE" ]; then | |
49 | print_usage | |
50 | exit 1 | |
51 | fi | |
52 | ||
53 | if [ ! -d "$TARGET" ]; then | |
54 | echo "$TARGET is not a valid target directory" | |
55 | exit 1 | |
56 | fi | |
57 | ||
58 | for i in "${!SOURCES[@]}"; do | |
59 | if [ "$i" == "$SOURCE" ]; then | |
60 | SOURCE_HOST=${SOURCES[$i]} | |
61 | fi | |
62 | done | |
63 | ||
64 | if [ -z "$SOURCE_HOST" ]; then | |
65 | echo -n "Please select one of the following sources:" | |
66 | for i in "${!SOURCES[@]}"; do | |
67 | echo -n " $i" | |
68 | done | |
69 | echo "" | |
70 | exit 1 | |
71 | fi | |
72 | ||
73 | RSYNC_OPTS="--stats --progress" | |
74 | if [ $SILENT -eq 1 ]; then | |
75 | RSYNC_OPTS="--quiet" | |
76 | fi | |
77 | ||
78 | # We start a two-stage sync here for DEB and RPM | |
79 | # Based on: https://www.debian.org/mirror/ftpmirror | |
80 | # | |
81 | # The idea is to prevent temporary situations where metadata points to files | |
82 | # which do not exist | |
83 | # | |
84 | ||
85 | # Exclude all metadata files | |
86 | rsync ${RSYNC_OPTS} ${SOURCE_HOST}::ceph --recursive --times --links \ | |
87 | --hard-links \ | |
88 | --exclude Packages* \ | |
89 | --exclude Sources* \ | |
90 | --exclude Release* \ | |
91 | --exclude InRelease \ | |
92 | --exclude i18n/* \ | |
93 | --exclude ls-lR* \ | |
94 | --exclude repodata/* \ | |
95 | ${TARGET} | |
96 | ||
97 | # Now also transfer the metadata and delete afterwards | |
98 | rsync ${RSYNC_OPTS} ${SOURCE_HOST}::ceph --recursive --times --links \ | |
99 | --hard-links --delete-after \ | |
100 | ${TARGET} |