1*da0073e9SAndroid Build Coastguard Worker#!/usr/bin/env bash 2*da0073e9SAndroid Build Coastguard Worker 3*da0073e9SAndroid Build Coastguard Workerset -eou pipefail 4*da0073e9SAndroid Build Coastguard Worker 5*da0073e9SAndroid Build Coastguard WorkerDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 6*da0073e9SAndroid Build Coastguard Workersource "${DIR}/promote/common_utils.sh" 7*da0073e9SAndroid Build Coastguard Worker 8*da0073e9SAndroid Build Coastguard Workerif [[ -z "${RESTORE_FROM:-}" ]]; then 9*da0073e9SAndroid Build Coastguard Worker echo "ERROR: RESTORE_FROM environment variable must be specified" 10*da0073e9SAndroid Build Coastguard Worker echo " example: RESTORE_FROM=v1.6.0-rc3 ${0}" 11*da0073e9SAndroid Build Coastguard Worker exit 1 12*da0073e9SAndroid Build Coastguard Workerfi 13*da0073e9SAndroid Build Coastguard Worker 14*da0073e9SAndroid Build Coastguard WorkerDRY_RUN=${DRY_RUN:-enabled} 15*da0073e9SAndroid Build Coastguard Worker 16*da0073e9SAndroid Build Coastguard WorkerPYTORCH_S3_BACKUP_BUCKET=${PYTORCH_S3_BACKUP_BUCKET:-s3://pytorch-backup/${RESTORE_FROM}} 17*da0073e9SAndroid Build Coastguard WorkerPYTORCH_S3_TEST_BUCKET=${PYTORCH_S3_TEST_BUCKET:-s3://pytorch/} 18*da0073e9SAndroid Build Coastguard WorkerPYTORCH_S3_FROM=${PYTORCH_S3_FROM:-${PYTORCH_S3_BACKUP_BUCKET}} 19*da0073e9SAndroid Build Coastguard WorkerPYTORCH_S3_TO=${PYTORCH_S3_TO:-s3://pytorch/} 20*da0073e9SAndroid Build Coastguard Worker 21*da0073e9SAndroid Build Coastguard Workerrestore_wheels() { 22*da0073e9SAndroid Build Coastguard Worker aws_promote torch whl 23*da0073e9SAndroid Build Coastguard Worker} 24*da0073e9SAndroid Build Coastguard Worker 25*da0073e9SAndroid Build Coastguard Workerrestore_libtorch() { 26*da0073e9SAndroid Build Coastguard Worker aws_promote libtorch-* libtorch 27*da0073e9SAndroid Build Coastguard Worker} 28*da0073e9SAndroid Build Coastguard Worker 29*da0073e9SAndroid Build Coastguard WorkerANACONDA="true anaconda" 30*da0073e9SAndroid Build Coastguard Workerif [[ ${DRY_RUN} = "disabled" ]]; then 31*da0073e9SAndroid Build Coastguard Worker ANACONDA="anaconda" 32*da0073e9SAndroid Build Coastguard Workerfi 33*da0073e9SAndroid Build Coastguard WorkerPYTORCH_CONDA_TO=${PYTORCH_CONDA_TO:-pytorch-test} 34*da0073e9SAndroid Build Coastguard Worker 35*da0073e9SAndroid Build Coastguard Workerupload_conda() { 36*da0073e9SAndroid Build Coastguard Worker local pkg 37*da0073e9SAndroid Build Coastguard Worker pkg=${1} 38*da0073e9SAndroid Build Coastguard Worker ( 39*da0073e9SAndroid Build Coastguard Worker set -x 40*da0073e9SAndroid Build Coastguard Worker ${ANACONDA} upload --skip -u "${PYTORCH_CONDA_TO}" "${pkg}" 41*da0073e9SAndroid Build Coastguard Worker ) 42*da0073e9SAndroid Build Coastguard Worker} 43*da0073e9SAndroid Build Coastguard Worker 44*da0073e9SAndroid Build Coastguard Workerexport -f upload_conda 45*da0073e9SAndroid Build Coastguard Worker 46*da0073e9SAndroid Build Coastguard Workerrestore_conda() { 47*da0073e9SAndroid Build Coastguard Worker TMP_DIR="$(mktemp -d)" 48*da0073e9SAndroid Build Coastguard Worker trap 'rm -rf ${TMP_DIR}' EXIT 49*da0073e9SAndroid Build Coastguard Worker ( 50*da0073e9SAndroid Build Coastguard Worker set -x 51*da0073e9SAndroid Build Coastguard Worker aws s3 cp --recursive "${PYTORCH_S3_BACKUP_BUCKET}/conda" "${TMP_DIR}/" 52*da0073e9SAndroid Build Coastguard Worker ) 53*da0073e9SAndroid Build Coastguard Worker export ANACONDA 54*da0073e9SAndroid Build Coastguard Worker export PYTORCH_CONDA_TO 55*da0073e9SAndroid Build Coastguard Worker # Should upload all bz2 packages in parallel for quick restoration 56*da0073e9SAndroid Build Coastguard Worker find "${TMP_DIR}" -name '*.bz2' -type f \ 57*da0073e9SAndroid Build Coastguard Worker | xargs -P 10 -I % bash -c "(declare -t upload_conda); upload_conda %" 58*da0073e9SAndroid Build Coastguard Worker} 59*da0073e9SAndroid Build Coastguard Worker 60*da0073e9SAndroid Build Coastguard Worker 61*da0073e9SAndroid Build Coastguard Workerrestore_wheels 62*da0073e9SAndroid Build Coastguard Workerrestore_libtorch 63*da0073e9SAndroid Build Coastguard Workerrestore_conda 64