infra/codestorage/hg-repo-sync

Paddy 2015-11-12 Parent:c8b4b952488a

4:32a993adf753 Go to Latest

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

Fix nested repository permissions. For repositories nested inside folders, fix the permissions on the folders so we can create other repositories inside them. Before, we only fixed the permissions on the repositories themselves; now we also fix the root directory that holds the repository.

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 if [[ "$target" == *\/* ]]
50 then
51 stripped_target=${target#*/}
52 stripped_target=${stripped_target%%/*}
53 echo "Changing ownership of /mounted/repos/${stripped_target}"
54 chgrp -R 2000 /mounted/repos/${stripped_target}
55 chmod -R 0770 /mounted/repos/${stripped_target}
56 fi
57 done
59 echo "Cleaning up..."
60 rm -rf /tmp/repos/*
62 echo "Pull complete."