infra/codestorage/hg-repo-sync

Paddy 2015-10-11 Parent:cc08c8ed2128 Child:c8b4b952488a

2:9cc2f3a01ab5 Go to Latest

infra/codestorage/hg-repo-sync/pull.sh

Use pip to install Mercurial, pin to 3.5.2 We want to use a relatively recent (but consistent) version of Mercurial, so I had to switch to using pip to install Mercurial, so I could pin it to version 3.5.2. apt-get didn't have version 3 available.

History
1 #!/bin/bash
2 today=$(date +%F)
4 yesterday=$(date --date yesterday +%F)
6 DOMAIN=${DOMAIN:-code.secondbit.org}
7 BACKUP_BUCKET=${BACKUP_BUCKET:-backups.$DOMAIN}
9 echo "Fixing permissions..."
10 chgrp -R 2000 /mounted/repos
12 echo "Cleaning up..."
13 rm -rf /tmp/repos/*
15 echo "Downloading bundles from gs://${BACKUP_BUCKET}/${today}"
17 output=$(gsutil cp -R gs://$BACKUP_BUCKET/$today/\* /tmp/repos 2>&1)
18 echo $output
20 bundles=$(find /tmp/repos -name '*.bundle')
22 # basically, if we get an error downloading the bundles, try for yesterday's
23 # this could happen if the pod restarts between the last upload of day A and the first upload of day B
24 if [[ $output == *"No URLs matched:"* ]]
25 then
26 echo "Downloading yesterday's bundles from gs://${BACKUP_BUCKET}/${yesterday}"
27 gsutil cp -R gs://$BACKUP_BUCKET/$yesterday/\* /tmp/repos
28 mv /tmp/repos/$yesterday /tmp/repos/$today
29 bundles=$(find /tmp/repos -name '*.bundle')
30 fi
32 for bundle in $bundles
33 do
34 dir=$(dirname $bundle)
35 stripped=${dir#.}
36 stripped=${stripped#/tmp/repos}
37 target=${bundle#/tmp/repos}
38 target=${target%.bundle}
39 if [ -d "/mounted/repos${target}" ]
40 then
41 echo "Pulling changes from $bundle to /mounted/repos$target"
42 hg --cwd /mounted/repos${target} pull $bundle
43 else
44 echo "Creating /mounted/repos$target repo from $bundle"
45 hg clone $bundle /mounted/repos${target}
46 chgrp -R 2000 /mounted/repos${target}
47 fi
48 done
50 echo "Cleaning up..."
51 rm -rf /tmp/repos/*
53 echo "Pull complete."