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