批量删除jira或者confluence项目

需求背景:

因为公司脱敏需求,需再搭建一套jira+confluence的环境。于是我用镜像起了一套。

新环境起来之后,需要删除已有的project。

手动删除效率低,于是考虑了批量删除的操作。

大致实现过程,记录如下:

1.1)先去jira Manage apps下载免费的Atlassian command line interface (CLI)
1.2)安装到jira服务器(我这边的场景是jira+confluence部署在同一台服务器上)

命令如下:

mkdir -p /opt/soft

cd /opt/soft
wget https://api.media.atlassian.com/file/15588a27-4330-4010-9024-1d86a4cfc092/binary?token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxYzZjOWRlMy05NDAyLTQwZjItYTM1YS0zYmM3MzVjOGQzNWMiLCJhY2Nlc3MiOnsidXJuOmZpbGVzdG9yZTpmaWxlOjE1NTg4YTI3LTQzMzAtNDAxMC05MDI0LTFkODZhNGNmYzA5MiI6WyJyZWFkIl19LCJleHAiOjE1Nzc1ODExODksIm5iZiI6MTU3NzQ5ODIwOX0.0wlAmSKCzMePlHHFGxsHIJfvxzNYPgPDvmwocNL2V8o&client=1c6c9de3-9402-40f2-a35a-3bc735c8d35c&name=atlassian-cli-9.1.0-distribution.zip

unzip atlassian-cli-9.1.0-distribution.zip
cd atlassian-cli-9.1.0
mv acli-server.properties acli.properties

cat acli.properties
# Example Server configuration - customize and rename this file to acli.properties

credentials = --user admin --password **********

myjira = jira -s http://jira.xxxx:8080 ${credentials}
myconfluence = confluence -s http://jira.xxxx.cn:8090 ${credentials}

# This defines the default client for actions, choose the most likely used client
#当你要进行Confluence的操作时,注释myjira那行。
#当你要进行Jira的操作时,注释myconfluence那行。
#default = ${myjira}
default = ${myconfluence}

##....删除jira略去

接下来记录的是删除Confluence project的过程。

前往cli官网,可以查看confluence example

https://bobswift.atlassian.net/wiki/spaces/CSOAP/pages/10584066/Examples

比如我们要删除单个project
--action removeSpace --space "zconfluencecliExport"

批量删除,我则写了一个脚本
首先sql获取一份所有项目的key,保存为txt
...sql命令略去
head space-key.txt
NT
NET
POR
UG
MK
UC
AOP
APP
123654

然后写一个shell脚本
cat confluence-del-spece.sh
#!/bin/bash
cat /opt/soft/atlassian-cli-9.1.0/space-key.txt|while read line
do
cd /opt/soft/atlassian-cli-9.1.0/ &&./acli.sh --action removeSpace --space $line
done

总结:

1)项目大的话,则删除过程,会比较长,需要用到nohub或者screen
我这边500个项目,大概花了12个小时。

原文地址:https://www.cnblogs.com/ccielife/p/12110992.html