]> git.openstreetmap.org Git - chef.git/blob - cookbooks/stateofthemap/templates/default/backup.cron.erb
Fail backup script on failures
[chef.git] / cookbooks / stateofthemap / templates / default / backup.cron.erb
1 #!/bin/bash
2
3 # DO NOT EDIT - This file is being maintained by Chef
4 set -euo pipefail
5
6 export ZSTD_CLEVEL=11
7 export ZSTD_NBTHREADS=0
8
9 T=$(mktemp -d -t -p /var/tmp sotm.XXXXXXXXXX)
10 D=$(date +%Y-%m-%d)
11 B="sotm-$D.tar.zst"
12
13 mkdir "$T/sotm-$D"
14
15 <% %w(2010 2011 2012).each do |year| -%>
16 echo '[mysqldump]' > "$T/mysqldump.opts"
17 echo 'user=sotm<%= year %>' >> "$T/mysqldump.opts"
18 echo 'password=<%= @passwords["sotm#{year}"] %>' >> "$T/mysqldump.opts"
19 mysqldump --defaults-file="$T/mysqldump.opts" --opt --no-tablespaces --max-allowed-packet=1G "sotm<%= year %>" > "$T/sotm-$D/sotm<%= year %>.sql"
20 <% end -%>
21
22 ln -s /srv/2010.stateofthemap.org "$T/sotm-$D/www2010"
23 ln -s /srv/2011.stateofthemap.org "$T/sotm-$D/www2011"
24 ln -s /srv/2012.stateofthemap.org "$T/sotm-$D/www2012"
25
26 nice tar --create --dereference --directory="$T" --sort=name "sotm-$D" | nice zstd --quiet --long --rsyncable -o "$T/$B"
27 nice rsync --preallocate --fuzzy "$T/$B" backup.openstreetmap.org::backup
28
29 rm -rf "$T"