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