Created
May 28, 2015 09:54
-
-
Save drscream/5402b4d597e046caf8d2 to your computer and use it in GitHub Desktop.
As most migration scripts it's ugly and run only one and thrown to trash after an successful run. Please be careful and run it in an save environment / folder. I run it on the new IMGAPI server so localhost:8080 could be used for the connection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Thomas Merkel <[email protected]> | |
# Migrate from datasets to IMGAPI. This script is build to migrate | |
# from the old datasets.at server to the new Joyent IMGAPI server. | |
# On other scripts you find the joyent-imgapi tool. I recommend using | |
# the imgapi-cli because it provides the feature of basic auth to the | |
# IMGAPI server. | |
IMGAPI_CLI='/opt/local/lib/node_modules/imgapi-cli/bin/imgapi-cli' | |
# Authentication user and password, separated by colon. If you use | |
# other authentication you could also set it to "none". | |
IMGAPI_CLI_AUTH='basic' | |
IMGAPI_AUTH='username:password' | |
# Source datasets server | |
DATASETS_SOURCE='http://datasets.dev.fruky.net' | |
# Download a list of all images on the server | |
UUIDS=$(curl -s ${DATASETS_SOURCE}/images | json -a uuid) | |
# Download image, extract and upload | |
for uuid in ${UUIDS}; do | |
curl -Os ${DATASETS_SOURCE}/api/export/${uuid} | |
tar xf ${uuid} | |
# Which files exists | |
files=$(tar tf ${uuid}) | |
# Workaround for the published_at date | |
sed -i 's|"published_at": "\(.*\)\.\([0-9]\{3\}\).*Z",|"published_at": "\1.\2Z",|g' *.dsmanifest | |
# Upload to IMGAPI | |
${IMGAPI_CLI} import --user ${IMGAPI_AUTH} -m *-imgapi.dsmanifest -f *.zfs.gz | |
# Cleanup | |
rm ${files} | |
rm ${uuid} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment