infra/codestorage/hg-repo-sync

Paddy 2015-10-14 Parent:cc08c8ed2128 Child:32a993adf753

3:c8b4b952488a Go to Latest

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

Remove the hgrc file, fix permissions. When pulling backups, make sure we set the permissions to 0770 as well as change the group they belong to. This caused us to not be able to write changes (oops). Also, remove the hgrc file. Which means our annoying "not trusting file /mounted/repos/blah-blah/.hg/hgrc from untrusted user root, group committers" message is back, but that's a minor nuisance. The real issue is that we're overwriting the hgrc for everything _anyways_ to get the push hook, etc. So there seemed to be little point.

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 fi
47 chgrp -R 2000 /mounted/repos${target}
48 chmod -R 0770 /mounted/repos${target}
49 done
51 echo "Cleaning up..."
52 rm -rf /tmp/repos/*
54 echo "Pull complete."