]> git.decadent.org.uk Git - dak.git/blob - config/homedir/syncdd.sh
Merge branch 'master' of ssh://ftp-master.debian.org/srv/ftp.debian.org/git/dak
[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/stages/ \
87         --delete \
88         --delete-after \
89         --timeout 3600 \
90         -e 'ssh -o ConnectTimeout=30 -o SetupTimeout=30' \
91         ftpmaster-sync:/srv/ftp-master.debian.org/ .
92
93     cd $public/
94     rsync -aH -B8192 \
95         --exclude mirror \
96         --exclude rsync/ \
97         --exclude=lost+found/ \
98         --exclude .da-backup.trace \
99         --exclude web-users/ \
100         --delete \
101         --delete-after \
102         --timeout 3600 \
103         -e 'ssh -o ConnectTimeout=30 -o SetupTimeout=30' \
104         ftpmaster-sync2:/srv/ftp.debian.org/ .
105
106 else
107     echo "Couldn't get the lock, not syncing"
108     exit 0
109 fi
110
111
112 ## ftpmaster-sync is defined in .ssh/config as:
113 # Host ftpmaster-sync
114 #   Hostname franck.debian.org
115 #   User dak
116 #   IdentityFile ~dak/.ssh/syncftpmaster
117 #   ForwardX11 no
118 #   ForwardAgent no
119 #   StrictHostKeyChecking yes
120 #   PasswordAuthentication no
121 #   BatchMode yes
122
123 ## ftpmaster-sync2 is the same, just a second ssh key