จากที่ Google Apps for Education หรือ Google Workspace for Education ปัจจุบัน ซึ่งจากเดิม ชูนโยบาย Unlimited Storage มาเป็น 100 GB ต่อ คน และ 100 TB ต่อ องค์กร — เพียงพอ ต่อการใช้งานเพื่อการศึกษาจริง ๆ ถ้าจัดการให้ดี
เหตุแห่งการเปลี่ยนแปลง
ผมว่า ก็เรา ๆ นี่แหล่ะ ใช้พื้นที่เค้าแบบไม่ใช่เพื่อการศึกษา ต้องยอมรับก่อน แล้วเรามาแก้ไขกัน
- มีบางคนในองค์กร เอาไปเก็บไฟล์หนัง ไม่เกี่ยวกับการศึกษา จริงหรือไม่ รู้อยู่แก่ใจ, เรื่องนี้ Super Admin ขององค์กรตรวจสอบได้ ด้วย Google Vault จัดการให้เด็ดขาด (Super Admin รายงานได้ ผู้มีอำนาจต้องตัดสินใจ … กล้าไม๊ ค่อยมาดูกัน)
- บางองค์กรไม่มีมาตรการควบคุมบัญชี สร้างมากเกินความจำเป็น แล้วบางคนเอาบัญชีไปขายใน Lazada, Shopee จริงไม่จริง รู้อยู่แก่ใจ
- บางคน เอาแต่ประโยชน์ส่วนตน ได้สิทธิ์ แต่เอาพื้นที่ Shared Drives ไปปล่อยให้ เว็บโป๊ เว็บหนังซีรี่ ใช้พื้นที่ซะงั้น
ก็เป็นธรรมดา Google ลงทุนทรัพยากร แต่ไม่ได้ใช้ให้ถูกตามวัตถุประสงค์ ก็ต้องมีการควบคุม งานส่วนตัว ใช้ My Drive, งานของหน่วยงาน ใช้ Shared Drives จบ
(บางคนบอกว่า ย้ายไป Microsoft OneDrive ก็ได้วะ 5TB … ทำเหมือนเดิม เดี๋ยวก็จะได้ผลเหมือนเดิม)
ผมได้เล่าไว้บ้างแล้ว เกี่ยวกับการใช้พื้นที่ของ Shared Drives
มาดูวิธีแก้ปัญหากันดีกว่า
- จากเดิม คนในสำนักงานก็จะชอบใช้ My Drive แล้ว Share ให้คนในหน่วยงานใช้กัน ก็เข้าใจได้ เพราะตอนแรกไม่มี Shared Drives เคยทำอย่างไรก็จะทำอย่างนั้น ไม่ชอบเปลี่ยนแปลง ถึงเวลาต้องเปลี่ยนแล้ว คือ งานส่วนรวม เอาไปเก็บใน Shared Drive
- เอาหล่ะ สมมุติว่า เราเคยใช้ Folder หนึ่ง เก็บสารพัดสิ่งที่เกี่ยวกับงานจริง ๆ แต่มันอยู่ใน My Drive (พื้นที่ส่วนตัว) สมมุติใช้ Folder ชื่อ parent ในนั้นมี Sub folder ย่อย และมีไฟล์ย่อย ๆ ซ้อน ๆ ลงไปจำนวนมาก
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-1024x359.png)
- แนะนำว่า แต่ละหน่วยงาน เช่น ระดับภาควิชา หรือ ระดับหน่วยงาน ไปสร้างพื้นที่ไว้บน Shared Drives
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-1-1024x359.png)
ปัญหาคือ … การย้ายไฟล์จาก Google Drives ไปยัง Shared Drives นั้น ทำได้ในระดับไฟล์ ไม่สามารถย้ายทั้ง Folder ได้
ใครใคร่ย้าย ก็เลือกไฟล์ แล้วคลิกขวา Move to ไป
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-2-1024x359.png)
แต่กรณี ของผมมีไฟล์ ที่สร้างจากอุปกรณ์ ขนาด 400-800 kb จำนวน …. 60 GB คิดคร่าว ๆ 2 ไฟล์ เป็น 1 MB ก็ราว ๆ 60 x 1024 x 2 = 122,880 ไฟล์
กรณีย้ายไฟล์จำนวนมากใน Folder เดียวกัน ไปไว้บน Shared Drives
ผมสร้าง Google Apps Script ไว้ที่ https://gist.github.com/nagarindkx/70f254a21c5cad7f964e762ab8b2e733
function moveFilesFromDriveToShareDrive() {
/*
Created by: Kanakorn Horsiritham
Digital Innovation and Data Analytics (DIDA)
Faculty of Medicine
Prince of Songkla University
Hatyai, Songkhla
THAILAND
*/
sourceFS=DriveApp.getFolderById('GoogleDrive-Folder-ID').getFiles()
destinationFS=DriveApp.getFolderById('SharedDrives-Folder-ID')
while(sourceFS.hasNext()){
f=sourceFS.next()
f.moveTo(destinationFS)
}
}
สิ่งที่ท่านต้องทำคือ
- เปิด Google Drive ต้นทางบน Web Browser แล้วดูที่ URL แล้ว Copy เฉพาะ GoogleDrive-Folder-ID เช่น
https://drive.google.com/drive/folders/GoogleDrive-Folder-ID
เก็บไว้ก่อน
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-3-1024x359.png)
2. เปิด Shared Drives ปลายทาง แล้วทำเหมือนกัน
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-4-1024x359.png)
3. จากนั้น สร้าง Google Apps Script ใน Google Drives
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-5-1024x417.png)
4. ตั้งชื่อ Project ว่า movefile1
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-6-1024x417.png)
5. copy code ข้างต้นมาใส่ จากนั้นแก้ไข GoogleDrive-Folder-ID และ SharedDrives-Folder-ID จากข้อ 1,2 แล้วกดปุ่ม Save
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-7-1024x417.png)
6. ถ้าไฟล์ไม่มากนัก ก็ เลือก moveFilesFromDriveToShareDrive กดปุ่ม Run
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-8-1024x417.png)
ถ้าทำครั้งแรก ระบบอาจจะถามอย่างนี้ ก็ให้เลือก Review Permissions แล้ว Next Next เลือก Account ไป (ขั้นนี้แล้ว ไม่อธิบายรายละเอียดแล้วนะครับ)
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-9.png)
จากนั้นก็รอไป Script จะทำงานต่อเนื่อง ยาวนานไม่เกิน 1800 วินาที หรือ 30 นาที ผลที่ได้คือ เฉพาะ Files เท่านั้น ที่จะย้ายไปอยู่ใน Shared Drives แต่ใจเย็น ๆ มีวิธีพาไปทั้งยวง รอแป๊บ
7. แต่ถ้ามีไฟล์จำนวนมาก จนครบ 30 นาทีแล้ว ก็ยังไม่หมด ก็ต้องอาศัย Trigger เพื่อสั่งให้ทำทุก ๆ 1 ชั่วโมง ดังนี้
เลื่อน Cursor ไปทางซ้ายมือ คลิกที่ Triggers
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-10-1024x395.png)
คลิกปุ่ม Add Trigger
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-11-1024x562.png)
เลือกตามนี้ แล้ว Save
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-12-1024x562.png)
จากนั้นก็รอไป ระบบจะทำจนหมดเวลา 30 นาที รออีก 1 ชั่วโมง แล้วก็ทำต่อไปเรื่อย ๆ
อันนี้ ของผม
![](https://sysadmin.psu.ac.th/wp-content/uploads/2021/05/image-13-1024x562.png)
ยังอีกยาวนาน
กรณีย้ายทั้ง Folder ไปไว้บน Shared Drives
UPDATE!!!!
เลือก Folder ต้นทาง และ ปลายทาง จากนั้น copy/move ได้เลย โดย ที่จะสร้างโครงสร้าง Folders และ Files ที่ Shared Drives ตามเดิมจากต้นทาง
ผมทำ Script ไว้ที่ https://gist.github.com/nagarindkx/e2897455b2ede2ae168f8cd5ccf16982
function copyFilesFromDriveToShareDrive() {
/*
Created by: Kanakorn Horsiritham
Digital Innovation and Data Analytics (DIDA)
Faculty of Medicine
Prince of Songkla University
Hatyai, Songkhla
THAILAND
*/
sourceID='GoogleDrive-Folder-ID'
destinationID='SharedDrives-Folder-ID'
copyFolder(sourceID, destinationID)
//moveFolder(sourceID, destinationID)
}
function copyFolder(sourceID, destinationID){
sFD = DriveApp.getFolderById(sourceID)
dFD = DriveApp.getFolderById(destinationID)
files = sFD.getFiles()
while(files.hasNext()) {
f=files.next()
if (! dFD.getFilesByName(f.getName()).hasNext()) {
f.makeCopy(f.getName(), dFD)
console.log('copy file: ' + f.getName())
} else {
Logger.log( "file: " + f.getName() + ' exist')
}
}
folders=sFD.getFolders()
nextlevel=[]
while(folders.hasNext()) {
fd = folders.next()
tmpDestinationFolder = dFD.getFoldersByName(fd.getName())
if (! tmpDestinationFolder.hasNext()) {
new_folder = dFD.createFolder(fd.getName())
Logger.log( "create folder: " + fd.getName())
} else {
new_folder = tmpDestinationFolder.next()
Logger.log( "folder: " + fd.getName() + ' exist')
}
nextlevel.push([fd.getId(), new_folder.getId()])
}
nextlevel.forEach(function(r){
copyFolder(r[0], r[1])
})
}
function moveFolder(sourceID, destinationID){
sFD = DriveApp.getFolderById(sourceID)
dFD = DriveApp.getFolderById(destinationID)
files = sFD.getFiles()
while(files.hasNext()) {
f=files.next()
if (! dFD.getFilesByName(f.getName()).hasNext()) {
console.log('file: ' + f.getName())
f.moveTo( dFD)
console.log('move file: ' + f.getName())
} else {
Logger.log( "file: " + f.getName() + ' exist')
}
}
folders=sFD.getFolders()
nextlevel=[]
c=0
if (folders.hasNext()) {
while(folders.hasNext()) {
fd = folders.next()
tmpDestinationFolder = dFD.getFoldersByName(fd.getName())
if (! tmpDestinationFolder.hasNext()) {
new_folder = dFD.createFolder(fd.getName())
} else {
new_folder = tmpDestinationFolder.next()
Logger.log( "folder: " + fd.getName() + ' exist')
}
nextlevel.push([fd.getId(), new_folder.getId()])
c=c+1
}
nextlevel.forEach(function(r){
moveFolder(r[0], r[1])
})
} else {
sFD.setTrashed(true)
}
}