{"id":77,"date":"2025-11-10T15:02:42","date_gmt":"2025-11-10T13:02:42","guid":{"rendered":"https:\/\/xavs.cat\/?p=77"},"modified":"2025-11-10T15:02:42","modified_gmt":"2025-11-10T13:02:42","slug":"descarrega-tots-els-artifacts-de-nexus","status":"publish","type":"post","link":"https:\/\/xavs.cat\/?p=77","title":{"rendered":"Descarrega tots els artifacts de Nexus"},"content":{"rendered":"\n<p>Un script que descarrega tots els artefactes d&#8217;un Nexus, per quan has de migrar una versi\u00f3 a una de nova, o per fer backup<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# ============================================================\n# Descarrega tots els artefactes d'un Nexus 3\n# fen servir la API REST oficial (no el browse HTML)\n# ============================================================\n\nNEXUS_URL=\"https:\/\/xxxx.xxxx.xxx\"\nREPO=\"cache\"\nDESTINACIO=\"\/data\/nexus\"\nUSUARI=\"admin\"\nTOKEN=\"xxxxx\"\n\nmkdir -p \"$DESTINACIO\"\ncd \"$DESTINACIO\" || exit 1\n\necho \"\ud83d\udce1 Obternir el llistat d'artefactes de $REPO en $NEXUS_URL...\"\n\n# Arxiu temporal per guardar la paginaci\u00f3\nNEXT_URL=\"$NEXUS_URL\/service\/rest\/v1\/assets?repository=$REPO\"\nCOUNT=0\n\nwhile &#91; -n \"$NEXT_URL\" ]; do\n  echo \"\u27a1\ufe0f  Consultant p\u00e0gina: $NEXT_URL\"\n  RESPONSE=$(curl -s -u \"$USUARI:$TOKEN\" \"$NEXT_URL\")\n  \n  # Extreu-re URLs de desc\u00e0rrega i seg\u00fcent p\u00e0gina\n  echo \"$RESPONSE\" | jq -r '.items&#91;].downloadUrl' >> urls.txt\n  NEXT_URL=$(echo \"$RESPONSE\" | jq -r '.properToken')\n  \n  if &#91; \"$NEXT_URL\" != \"null\" ] &amp;&amp; &#91; -n \"$NEXT_URL\" ]; then\n    NEXT_URL=\"$NEXUS_URL\/service\/rest\/v1\/assets?repository=$REPO&amp;properToken=$NEXT_URL\"\n  else\n    NEXT_URL=\"\"\n  fi\ndone\n\nTOTAL=$(wc -l &lt; urls.txt)\necho \"\u2705 S'han trovat $TOTAL artefactes. Comencem.\"\n\n# Descarrega cada artefacte preservant estructura de carpetes\nwhile IFS= read -r URL; do\n  REL_PATH=$(echo \"$URL\" | sed \"s|.*\/$REPO\/||\")\n  DIR=$(dirname \"$REL_PATH\")\n  mkdir -p \"$DIR\"\n  COUNT=$((COUNT + 1))\n  echo \"\u2b07\ufe0f  &#91;$COUNT] $REL_PATH\"\n  curl -s -u \"$USUARI:$TOKEN\" -o \"$REL_PATH\" \"$URL\"\ndone &lt; urls.txt\n\necho \"\ud83c\udfaf Desc\u00e0rrega finalitzada. Artefactes guardats en $DESTINACIO\"\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Un script que descarrega tots els artefactes d&#8217;un Nexus, per quan has de migrar una versi\u00f3 a una de nova, o per fer backup<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[27,28],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-general","tag-maven","tag-nexus"],"_links":{"self":[{"href":"https:\/\/xavs.cat\/index.php?rest_route=\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xavs.cat\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xavs.cat\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xavs.cat\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xavs.cat\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=77"}],"version-history":[{"count":1,"href":"https:\/\/xavs.cat\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":78,"href":"https:\/\/xavs.cat\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions\/78"}],"wp:attachment":[{"href":"https:\/\/xavs.cat\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xavs.cat\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xavs.cat\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}