]> git.decadent.org.uk Git - dak.git/blob - config/homedir/syncdd.sh
570e3469609d7d481a96e9876a990864bb26a586
[dak.git] / config / homedir / syncdd.sh
1 #!/bin/bash
2
3 # Copyright (C) 2011 Joerg Jaspert <joerg@debian.org>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; version 2.
8 #
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
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 EXTRA=""
30
31 check_commandline() {
32     while [ $# -gt 0 ]; do
33         case "$1" in
34             sync)
35                 EXTRA="--exclude ftp/"
36                 ;;
37             pool)
38                 ;;
39             *)
40                 echo "Unknown option ${1} ignored"
41                 ;;
42         esac
43         shift  # Check next set of parameters.
44     done
45 }
46
47 if [ $# -gt 0 ]; then
48     ORIGINAL_COMMAND=$*
49 else
50     ORIGINAL_COMMAND=""
51 fi
52
53 SSH_ORIGINAL_COMMAND=${SSH_ORIGINAL_COMMAND:-""}
54 if [ -n "${SSH_ORIGINAL_COMMAND}" ]; then
55     set "nothing" "${SSH_ORIGINAL_COMMAND}"
56     shift
57     check_commandline $*
58 fi
59
60 if [ -n "${ORIGINAL_COMMAND}" ]; then
61     set ${ORIGINAL_COMMAND}
62     check_commandline $*
63 fi
64
65
66 cleanup() {
67     rm -f "${HOME}/sync.lock"
68 }
69 trap cleanup EXIT TERM HUP INT QUIT
70
71 # not using $lockdir as thats inside the rsync dir, and --delete would
72 # kick the lock away. Yes we could exclude it, but wth bother?
73 #
74 # Also, NEVER use --delete-excluded!
75 if lockfile -r3 ${HOME}/sync.lock; then
76     cd $base/
77     rsync -aH -B8192 \
78         --exclude backup/*.xz \
79         --exclude backup/dump* \
80         --exclude database/\*.db \
81         ${EXTRA} \
82         --exclude mirror \
83         --exclude morgue/ \
84         --exclude=lost+found/ \
85         --exclude .da-backup.trace \
86         --exclude lock/new/ \
87         --exclude lock/stages/ \
88         --exclude queue/holding/ \
89         --exclude queue/newstage/ \
90         --exclude queue/unchecked/ \
91         --exclude tmp/ \
92         --delete \
93         --delete-after \
94         --timeout 3600 \
95         -e 'ssh -o ConnectTimeout=30 -o SetupTimeout=30' \
96         ftpmaster-sync:/srv/ftp-master.debian.org/ .
97
98     cd $public/
99     rsync -aH -B8192 \
100         --exclude mirror \
101         --exclude rsync/ \
102         --exclude=lost+found/ \
103         --exclude .da-backup.trace \
104         --exclude web-users/ \
105         --delete \
106         --delete-after \
107         --timeout 3600 \
108         -e 'ssh -o ConnectTimeout=30 -o SetupTimeout=30' \
109         ftpmaster-sync2:/srv/ftp.debian.org/ .
110
111 else
112     echo "Couldn't get the lock, not syncing"
113     exit 0
114 fi
115
116
117 ## ftpmaster-sync is defined in .ssh/config as:
118 # Host ftpmaster-sync
119 #   Hostname franck.debian.org
120 #   User dak
121 #   IdentityFile ~dak/.ssh/syncftpmaster
122 #   ForwardX11 no
123 #   ForwardAgent no
124 #   StrictHostKeyChecking yes
125 #   PasswordAuthentication no
126 #   BatchMode yes
127
128 ## ftpmaster-sync2 is the same, just a second ssh key