-
Notifications
You must be signed in to change notification settings - Fork 24
/
migrate_filestorage.sh
37 lines (32 loc) · 1.18 KB
/
migrate_filestorage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash
# Migrate the data from S3 FileStorage to local fyle system
# FileStorage Server Eg: https://cc-p-minio.ckan.io or https://s3.amazonaws.com
HOST=${1}
ACCESS_KEY=${2}
SECRET_KEY=${3}
BUCKET=${4}
STORAGE_PREFIX=${5}/
TMP_DATA_RECEIVED='/tmp/data_received'
TMP_DATA='/tmp/data'
# Download minio client
wget https://dl.min.io/client/mc/release/linux-amd64/mc && chmod +x mc
# Add host
./mc config host add filestorage $HOST $ACCESS_KEY $SECRET_KEY
echo downloading from storage
./mc cp --recursive filestorage/$BUCKET/$STORAGE_PREFIX $TMP_DATA_RECEIVED
echo updating paths
for dir in $(ls $TMP_DATA_RECEIVED/resources); do
FIRST_DIR=${dir:0:3}
SECOND_DIR=${dir:3:3}
REST=${dir:6}
RESOURCE_DIR=$TMP_DATA/resources/$FIRST_DIR/$SECOND_DIR
mkdir -p $RESOURCE_DIR
for file in $TMP_DATA_RECEIVED/resources/$dir/*; do
echo $file
cp $file $RESOURCE_DIR/$REST
done
done
cp -r $TMP_DATA_RECEIVED/storage $TMP_DATA/storage
echo mounting data into the persistent volumes
docker cp $TMP_DATA ckan-cloud-docker_ckan_1:/var/lib/ckan
docker-compose -f docker-compose.yaml -f .docker-compose-db.yaml -f .docker-compose.${5}-theme.yaml exec -u root ckan chown -R ckan:ckan /var/lib/ckan