アプリをまるごとクローンしたい(データも)

現在運用中のアプリのうち一つ(Aアプリとする)をデータを含めクローンして(Bアプリとする)それぞれ別アプリとして分岐して並行運用を開始したいと思っています。

条件
・Aアプリのデータの全レコードをBアプリに引き継ぐ
・データのうちには、複数項目の添付ファイルも含まれる
・データのうちには、表形式も含まれる
・Aアプリのレコード数は約150レコード
・AアプリとBアプリはクローン後一切関連しない
・Bアプリはゲストスペースのアプリとする
・コメントと履歴は引き継がない(引き継いでも良い)
・レコードNO.は再度採番されて良い

どうやら基本機能には搭載されていないようですが、これを実現したく、可能となる方法を探しています。
ご存知の方いらっしゃいますでしょうか。

ひらのさん

お世話になっております。

こちらのツールで可能かと思います。
https://developer.cybozu.io/hc/ja/community/posts/900001394706

インポート時に-gオプションを付ければ、ゲストスペースにも利用できます。
https://www.npmjs.com/package/kintone-app-template#options

江田さん

ありがとうございます!

本番環境しか持ち合わせておらず、初めてのことで試すのが怖いのですが、私がいう「A」アプリが上書きされたり何らかの変更がされることはありますか。また、誤って「i」オプションを2回連続実施した場合、「A」も「B」もそのままで、さらに別なアプリが作成されるということでしょうか。

ひらのさん

お世話になっております。

>「A」アプリが上書きされたり何らかの変更がされることはありますか
「A」アプリに対しての変更処理は一切ありません。

>誤って「i」オプションを2回連続実施した場合、「A」も「B」もそのままで、さらに別なアプリが作成されるということでしょうか
はい、仰る通りです。

「e」オプションで実行した際は、「A」アプリのデータを参照し、JSONを作成するだけです。kintoneに対する変更はありません。
「i」オプションで実行した際は、JSONをもとに新規アプリを作成します。既存アプリに対する変更はありません。
既存アプリに対しての変更、削除処理はないのでご安心いただければと思います。

オープンソースですので、こちらからご確認いただければと思います。
https://github.com/Atsushi-Eda/kintone-app-template

江田さん

ご回答ありがとうございます。安心しました。

実行してみました。気づいたことです。

・カテゴリー機能を使っているアプリで、一覧にカテゴリー項目を指定していると i できない。
→ 一時的にこれを解除して対応しました。

・以下エラーが発生して、全体の半分くらいのレコードが反映された時点で i  が失敗する。
→ データが悪いのでしょうか、、私では調査が難しかったので、一旦ここまでとしました。いろいろとありがとうございます。

- Add records.(node:20068) UnhandledPromiseRejectionWarning: KintoneAllRecordsError: 0/4 records are processed successfully
at new KintoneAllRecordsError (C:\Users\username\AppData\Roamingpm-cache\_npx\11884ode_modules\kintone-app-templateode_modules\@kintone\rest-api-client\lib\error\KintoneAllRecordsError.js:26:24)
at RecordClient.<anonymous> (C:\Users\username\AppData\Roamingpm-cache\_npx\11884ode_modules\kintone-app-templateode_modules\@kintone\rest-api-client\lib\client\RecordClient.js:507:31)
at step (C:\Users\username\AppData\Roamingpm-cache\_npx\11884ode_modules\kintone-app-templateode_modules\@kintone\rest-api-client\lib\client\RecordClient.js:44:23)
at Object.throw (C:\Users\username\AppData\Roamingpm-cache\_npx\11884ode_modules\kintone-app-templateode_modules\@kintone\rest-api-client\lib\client\RecordClient.js:25:53)
at rejected (C:\Users\username\AppData\Roamingpm-cache\_npx\11884ode_modules\kintone-app-templateode_modules\@kintone\rest-api-client\lib\client\RecordClient.js:17:65)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:20068) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:20068) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

 

ひらのさん

お世話になっております。

バグがあったということで、失礼いたしました。
貴重なコメントありがとうございます。

> カテゴリー機能を使っているアプリで、一覧にカテゴリー項目を指定していると i できない
なるほど、仰る通りですね。
カテゴリーはkintone REST APIでは対応していないので、インポート時に除去していたつもりでしたが、一覧に設定されている可能性を考慮できておりませんでした。
一旦は一覧のカテゴリーを除去していただく対応でお願いします。

> 全体の半分くらいのレコードが反映された時点で i  が失敗する
恐らくレコードに何らかの問題があるのかと思います。
ただ、エラーハンドリングしていなかったので、何が問題かわからないですよね。

version 1.0.2でレコード追加時にエラーハンドリングさせるよう変更しました。
kintone-app-templateを再インストールしてご確認いただけますか。(npxで実行している場合は以前と同じく実行すれば大丈夫です)

エラーのindexとmessageが表示されるかと思います。
indexが何番目に追加しようとしているレコードであるかという情報です。
「index + 1」のレコード番号にあたるAアプリのレコードに問題があるかと思うので、そちらをご確認いただければと思います。

江田さん

ありがとうございます!早速試してみました。

今度は e がエラーとなりました。

429と出ていたので、今回のターゲットではない小さいアプリに対して  e してみるとうまくいくようです。
きちんと切り分けしていませんが、レコード数に因果関係があるように感じています。

※もちろん治してくださいとうお願いではなく、実行結果や動作状況の報告であります。もし、ここではなくてgithubのissueなどの方が適切であれば移動します。(今、github落ちててビビりました)
いろいろとありがとうございます。

C:\tmp>node --version
v14.17.0

C:\tmp>npm --version
7.16.0

C:\tmp>npx --version
7.16.0

C:\tmp>npx kintone-app-template e 5 -d (SNIP).cybozu.com -u (SNIP) -p (SNIP)
Need to install the following packages:
kintone-app-template
Ok to proceed? (y) y
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated request-promise@4.2.6: request-promise has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
\ Get files.(node:28632) UnhandledPromiseRejectionWarning: KintoneRestAPIError: [429] [undefined] (undefined)
at KintoneResponseHandler.handleErrorResponse (C:\Users\hiran\AppData\Localpm-cache\_npx\968b047842594d57ode_modules\@kintone\rest-api-client\lib\KintoneResponseHandler.js:57:15)
at C:\Users\hiran\AppData\Localpm-cache\_npx\968b047842594d57ode_modules\@kintone\rest-api-client\lib\KintoneResponseHandler.js:35:123
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Function.download (C:\Users\hiran\AppData\Localpm-cache\_npx\968b047842594d57ode_modules\kintone-app-template\src\export\FileDownloader.js:15:9)
at async Promise.all (index 648)
at async C:\Users\hiran\AppData\Localpm-cache\_npx\968b047842594d57ode_modules\kintone-app-template\src\export\index.js:76:17
(Use `node --trace-warnings ...` to show where the warning was created)
(node:28632) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:28632) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

ひらのさん

お世話になっております.

ご丁寧にありがとうございます.
ファイルダウンロード処理でkintone REST APIの同時接続数制限にかかってしまっているようですね.
https://developer.cybozu.io/hc/ja/articles/360020272112
考慮不足でした.

version 1.0.4が修正版になるので、お手数ですがご確認いただければと思います。
あまり考えずに100リクエストずつ処理するようにしたので、他でkintone REST APIを利用しているタイミングと被るとうまく行かない可能性がありますが…

> githubのissueなどの方が適切であれば移動します
たしかに、そちらの方が適切かもしれませんね。お手数でなければ次回はそちらからお願いいたします。

江田さん

成功しました!

当初の i がエラーとなった件は、権限不足が原因でした。実施ユーザの「アプリのアクセス権」は、削除権限が付与されていませんでしたが、削除権限をつけてから e して i したらエラーなく取り込めました。

(エラーが発生したときの様子)

C:\tmp>npx kintone-app-template i template.json -d (SNIP).cybozu.com -u (SNIP) -p (SNIP) -g (SNIP)
/ Add records.index: undefined, message: [403] [CB_NO02] 権限がありません。 (SNIP)
Added 1 apps.
┌────┬─────┐
│ (index)│ appId │
├────┼─────┤
│ 0 │ '(SNIP)' │
└────┴─────┘

これで、ポチポチ全部コピーせずに済みます。相当な作業時間の削減になりました。このツールの本来の使用用途とは違う使い方でしたが、最後まで対応いただき大変助かりました。

感謝。

このトピックはベストアンサーに選ばれた返信から 3 日が経過したので自動的にクローズされました。新たに返信することはできません。