{"id":4502,"date":"2021-07-03T12:58:49","date_gmt":"2021-07-03T03:58:49","guid":{"rendered":"\/blog\/?p=4502"},"modified":"2023-09-21T09:26:32","modified_gmt":"2023-09-21T00:26:32","slug":"rclone-onedrive-%ea%b3%bc%ea%b1%b0-%eb%b2%84%ec%a0%84-%ec%b4%88%ea%b8%b0%ed%99%94-%ec%8a%a4%ed%81%ac%eb%a6%bd%ed%8a%b8","status":"publish","type":"post","link":"https:\/\/hasu0707.duckdns.org\/blog\/?p=4502","title":{"rendered":"[rclone]OneDrive Business \uacfc\uac70 \ubc84\uc804 \ucd08\uae30\ud654 \uc2a4\ud06c\ub9bd\ud2b8"},"content":{"rendered":"\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n###########################################################\n#\n# onedrive_cleanup.sh\n# \uc6d0\ub4dc\ub77c\uc774\ube0c \uc6a9\ub7c9 \ud655\ubcf4\ub97c \uc704\ud574 \uc800\uc7a5\ub41c \ubaa8\ub4e0 \ubc84\uc804\uc744 \uc81c\uac70\ud55c\ub2e4.\n#\n###########################################################\n\nREMOTE=\"onedrive\"\n\nrclone about \"${REMOTE}:\"\nACCESS_TOKEN=\"$(rclone config dump | jq -r --arg remote \"$REMOTE\" '.[$remote].token | fromjson | .access_token')\"\nDRIVE_ID=\"$(rclone config dump | jq -r --arg remote \"$REMOTE\" '.[$remote].drive_id')\"\n\nfunction get_dir {\n    ITEM_ID=\"$1\"\n\n    echo \"Listing directory: ${ITEM_ID}\"\n    curl -s \\\n      -X 'GET' \\\n      -H \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n      -H 'Accept: application\/json' \\\n      \"https:\/\/graph.microsoft.com\/v1.0\/drives\/${DRIVE_ID}\/items\/${ITEM_ID}\/children\" \\\n      | jq -r '.value[] | \"\\(if (.file != null) then \"file\" else \"directory\" end) \\(.id)\"' \\\n      | while read -r TYPE ID; do\n            if [[ \"$TYPE\" == \"file\" ]]; then\n                get_versions \"$ID\"\n            else\n                get_dir \"$ID\"\n            fi\n        done\n}\n\nfunction get_versions {\n    ITEM_ID=\"$1\"\n\n    echo \"Checking versions for: ${ITEM_ID}\"\n    curl -s \\\n      -X 'GET' \\\n      -H \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n      -H 'Accept: application\/json' \\\n      \"https:\/\/graph.microsoft.com\/v1.0\/drives\/${DRIVE_ID}\/items\/${ITEM_ID}\/versions\" \\\n    | jq -r '.value[].id' \\\n    | tail -n+2 \\\n    | while read -r VERSION_ID; do\n          echo \"Removing version: ${VERSION_ID}\"\n\n          curl -s \\\n            -X 'DELETE' \\\n            -H \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n            -H 'Accept: application\/json' \\\n            \"https:\/\/graph.microsoft.com\/v1.0\/drives\/${DRIVE_ID}\/items\/${ITEM_ID}\/versions\/${VERSION_ID}\"\n      done\n}\n\nget_dir root<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[15],"tags":[],"class_list":["post-4502","post","type-post","status-publish","format-standard","hentry","category-computing_tools"],"_links":{"self":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4502"}],"version-history":[{"count":0,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4502\/revisions"}],"wp:attachment":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}