sync-dd 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #! /bin/bash
  2. # Copyright (C) 2011,2013, Joerg Jaspert <joerg@debian.org>
  3. # Copyright (C) 2012, Ansgar Burchardt <ansgar@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. set -e
  18. set -u
  19. set -E
  20. export LANG=C
  21. export LC_ALL=C
  22. export SCRIPTVARS=/srv/ftp-master.debian.org/dak/config/debian/vars
  23. . $SCRIPTVARS
  24. usage() {
  25. echo "usage: $0 <lock> <host1> <host2> sync|code <timeout=30m>"
  26. echo
  27. echo "sync dd-accessible copy of the archive"
  28. echo
  29. echo "arguments:"
  30. echo " lock: file used for locking"
  31. echo " host1: hostname for syncing /srv/ftp-master.debian.org"
  32. echo " host2: hostname for syncing /srv/ftp.debian.org"
  33. echo " sync|code: sync syncs everything"
  34. echo " timeout: timeout for rsync, see man:timeout(1)"
  35. echo " code only syncs the dak/ directory (uses host1 value as target)"
  36. exit ${1:-0}
  37. }
  38. if [ $# -lt 4 ]; then
  39. usage 1
  40. fi
  41. lockfile="${lockdir}/${1}"
  42. host1="${2}"
  43. host2="${3}"
  44. mode="${4}"
  45. timeout="${5:-30m}"
  46. # extra options for rsync of /srv/ftp-master.debian.org
  47. extra1=""
  48. cleanup() {
  49. rm -f "${lockfile}"
  50. }
  51. trap cleanup EXIT TERM HUP INT QUIT
  52. # Also, NEVER use --delete-excluded!
  53. if lockfile -r3 "${lockfile}" 2> /dev/null; then
  54. case "${mode}" in
  55. sync)
  56. timeout "${timeout}" \
  57. rsync -aH -B8192 \
  58. ${extra1} \
  59. --exclude "/.nobackup" \
  60. --exclude "/archive/" \
  61. --exclude "/backup/*.xz" \
  62. --exclude "/backup/dump*" \
  63. --exclude "/build-queues/" \
  64. --exclude "/database/*.db" \
  65. --exclude ".da-backup.trace" \
  66. --exclude "/export/changelogs/tmp*/" \
  67. --exclude "/ftp" \
  68. --exclude "lost+found" \
  69. --exclude "/lock/" \
  70. --exclude "/mirror" \
  71. --exclude "/morgue/" \
  72. --exclude "/queue/bts_version_track/" \
  73. --exclude "/queue/unchecked/" \
  74. --exclude "/s3kr1t" \
  75. --exclude "/scripts/s3kr1t" \
  76. --exclude "/tmp/" \
  77. --exclude "/public/incoming.debian.org" \
  78. --exclude "/tiffani/" \
  79. --delete --delete-after \
  80. -e 'ssh -o ConnectTimeout=30 -o SetupTimeout=30' \
  81. /srv/ftp-master.debian.org/ "${host1}:/srv/ftp-master.debian.org/"
  82. # command for the remote side:
  83. # command="rsync --server -lHogDtpre.iLsf -B8192 --timeout=3600 --delete-after . /srv/ftp-master.debian.org/"
  84. timeout "${timeout}" \
  85. rsync -aH -B8192 \
  86. --exclude "/.nobackup" \
  87. --exclude mirror \
  88. --exclude rsync/ \
  89. --exclude lost+found \
  90. --exclude .da-backup.trace \
  91. --exclude web-users/ \
  92. --delete --delete-after \
  93. -e 'ssh -o ConnectTimeout=30 -o SetupTimeout=30' \
  94. /srv/ftp.debian.org/ "${host2}:/srv/ftp.debian.org/"
  95. # command for the remote side:
  96. # command="rsync --server -lHogDtpre.iLsf -B8192 --timeout=3600 --delete-after . /srv/ftp.debian.org/"
  97. ;;
  98. code)
  99. timeout "${timeout}" \
  100. rsync -aH -B8192 \
  101. --exclude "/.nobackup" \
  102. --delete --delete-after \
  103. -e 'ssh -o ConnectTimeout=30 -o SetupTimeout=30' \
  104. /srv/ftp-master.debian.org/dak/ "${host1}:/srv/ftp-master.debian.org/dak/"
  105. # command for the remote side:
  106. # command="rsync --server -lHogDtpre.iLsf -B8192 --timeout=3600 --delete-after . /srv/ftp-master.debian.org/dak/"
  107. ;;
  108. *)
  109. echo "Unknown mode ${mode}." >&2
  110. exit 1
  111. ;;
  112. esac
  113. else
  114. #echo "Couldn't get the lock, not syncing"
  115. exit 0
  116. fi