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