]> git.decadent.org.uk Git - dak.git/blob - scripts/debian/sync-dd
405f06c87b5cfc9f5153993f5089131bf21b6cd8
[dak.git] / scripts / debian / sync-dd
1 #! /bin/bash
2
3 # Copyright (C) 2011,2013, Joerg Jaspert <joerg@debian.org>
4 # Copyright (C) 2012, Ansgar Burchardt <ansgar@debian.org>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; version 2.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 set -e
20 set -u
21 set -E
22
23 export LANG=C
24 export LC_ALL=C
25
26 export SCRIPTVARS=/srv/ftp-master.debian.org/dak/config/debian/vars
27 . $SCRIPTVARS
28
29 usage() {
30   echo "usage: $0 <lock> <host1> <host2> sync|pool"
31   echo
32   echo "sync dd-accessible copy of the archive"
33   echo
34   echo "arguments:"
35   echo "  lock:      file used for locking"
36   echo "  host1:     hostname for syncing /srv/ftp-master.debian.org"
37   echo "  host2:     hostname for syncing /srv/ftp.debian.org"
38   echo "  sync|pool: sync excludes ftp/, pool syncs ftp/ too"
39   exit ${1:-0}
40 }
41
42 if [ $# -ne 4 ]; then
43   usage 1
44 fi
45
46 lockfile="${lockdir}/${1}"
47 host1="${2}"
48 host2="${3}"
49 mode="${4}"
50
51 # extra options for rsync of /srv/ftp-master.debian.org
52 extra1=""
53
54 case "${mode}" in
55     sync)
56         extra1="${extra1} --exclude /ftp/"
57         ;;
58     pool)
59         ;;
60     *)
61         echo "Unknown mode ${mode}." >&2
62         exit 1
63         ;;
64 esac
65
66 cleanup() {
67   rm -f "${lockfile}"
68 }
69 trap cleanup EXIT TERM HUP INT QUIT
70
71 # Also, NEVER use --delete-excluded!
72 if lockfile -r3 "${lockfile}"; then
73     rsync -aH -B8192 \
74         ${extra1} \
75         --exclude "/backup/*.xz" \
76         --exclude "/backup/dump*" \
77         --exclude "/build-queues/" \
78         --exclude "/database/*.db" \
79         --exclude ".da-backup.trace" \
80         --exclude "lost+found" \
81         --exclude "/lock/" \
82         --exclude "/mirror/" \
83         --exclude "/morgue/" \
84         --exclude "/queue/bts_version_track/" \
85         --exclude "/queue/unchecked/" \
86         --exclude "/s3kr1t" \
87         --exclude "/scripts/s3kr1t" \
88         --exclude "/tmp/" \
89         --delete --delete-after \
90         --timeout 3600 \
91         -e 'ssh -o ConnectTimeout=30 -o SetupTimeout=30' \
92         /srv/ftp-master.debian.org/ "${host1}:/srv/ftp-master.debian.org/"
93    # command for the remote side:
94    # command="rsync --server -lHogDtpre.iLsf -B8192 --timeout=3600 --delete-after . /srv/ftp-master.debian.org/"
95
96    rsync -aH -B8192 \
97        --exclude mirror \
98        --exclude rsync/ \
99        --exclude lost+found \
100        --exclude .da-backup.trace \
101        --exclude web-users/ \
102        --delete --delete-after \
103        --timeout 3600 \
104        -e 'ssh -o ConnectTimeout=30 -o SetupTimeout=30' \
105        /srv/ftp.debian.org/ "${host2}:/srv/ftp.debian.org/"
106    # command for the remote side:
107    # command="rsync --server -lHogDtpre.iLsf -B8192 --timeout=3600 --delete-after . /srv/ftp.debian.org/"
108
109    if [[ ${mode} == pool ]]; then
110        # Sync backports
111        rsync -aH -B8192 \
112            --delete --delete-after \
113            --timeout 3600 \
114            -e 'ssh -o ConnectTimeout=30 -o SetupTimeout=30' \
115            /srv/backports-master.debian.org/mirror/ \
116            ries-sync3:/srv/backports.debian.org/htdocs/debian-backports/
117        # And now tell static.debian.org that something changed
118        /usr/local/bin/static-update-component backports.debian.org
119    fi
120 else
121     echo "Couldn't get the lock, not syncing"
122     exit 0
123 fi