Quản lý các tệp xuất ra

Vault API cho phép bạn quản lý các tệp xuất của Google Vault. Bạn có thể thực hiện các tác vụ sau:

  • Tạo tệp xuất. Gửi yêu cầu đến Vault để tìm các tin nhắn hoặc tệp phù hợp với truy vấn của bạn và xuất các tin nhắn hoặc tệp đó sang Google Cloud.

    Bạn có thể có tối đa 20 tệp xuất chạy cùng lúc trong tổ chức. Để xuất nhanh hơn, hãy chia các tệp xuất lớn thành các tệp nhỏ hơn. Ví dụ: xuất dữ liệu theo tháng thay vì xuất tất cả cùng một lúc. Một lựa chọn khác là đưa ít mục hơn (chẳng hạn như người dùng, nhóm hoặc không gian trò chuyện) vào mỗi tệp xuất. Các tệp xuất có sẵn trong 15 ngày sau khi tạo. Sau thời gian này, các tệp xuất sẽ bị xoá và không còn truy cập được nữa.

    Các ví dụ sau đây cho thấy cách tạo tệp xuất cho các dịch vụ khác nhau:

  • Liệt kê tệp xuất. Truy xuất trạng thái của tất cả các tệp xuất được liên kết với một vụ việc.

  • Lấy tệp xuất. Truy xuất thông tin về một tệp xuất.

  • Tải tệp xuất xuống. Tải một tệp xuất xuống từ Google Cloud.

  • Xoá tệp xuất. Xoá tệp xuất khỏi một vụ việc khi không còn cần nữa.

Trước khi bắt đầu

Để thiết lập các thư viện và phương thức xác thực bắt buộc, hãy làm theo hướng dẫn bắt đầu nhanh cho ngôn ngữ lập trình của bạn.

Để làm việc với các tài nguyên của Vault, một tài khoản phải có các đặc quyền bắt buộc của Vault và quyền truy cập vào vụ việc. Để truy cập vào một vụ việc, tài khoản phải tạo vụ việc đó, được chia sẻ vụ việc đó hoặc có đặc quyền Xem tất cả vụ việc.

Tạo tệp xuất Gmail

Ví dụ sau đây cho thấy cách tạo tệp xuất Gmail. Yêu cầu này xuất tất cả tin nhắn trên Gmail và Hangouts phiên bản cũ đáp ứng các tiêu chí sau:

  • Tin nhắn thuộc sở hữu của các tài khoản email1email2.
  • Không bao gồm tin nhắn nháp.
  • Tin nhắn được gửi đến ceo@solarmora.com.

Các ví dụ này sử dụng hệ thống xuất Gmail cũ. Để xuất bằng hệ thống xuất mới, trong MailExportOptions, hãy đặt useNewExport thành true.

Java

public Export createMailAccountHeldDataExports(Vault client, String matterId) {
  AccountInfo emailsToSearch = new AccountInfo().setEmails(ImmutableList.of("email1", "email2"));
  MailOptions mailQueryOptions = new MailOptions().setExportFormat("PST");
  String queryTerms = "to:ceo@solarmora.com";
  Query mailQuery =
      new Query()
          .setCorpus("MAIL")
          .setDataScope("HELD_DATA")
          .setSearchMethod("ACCOUNT")
          .setAccountInfo(emailsToSearch)
          .setTerms(queryTerms)
          .setMailOptions(mailQueryOptions);
  MailExportOptions mailExportOptions =
      new MailExportOptions()
          .setExportFormat("MBOX")
          .showConfidentialModeContent(true);
  Export wantedExport =
      new Export()
          .setMatterId(matterId)
          .setName("My first mail accounts export")
          .setQuery(mailQuery)
          .setExportOptions(new ExportOptions().setMailOptions(mailExportOptions));
  return client.matters().exports().create(matter, wantedExport).execute();
}

Python

def create_mail_account_held_data_export(service, matter_id):
  emails_to_search = ['email1', 'email2']
  mail_query_options = {'excludeDrafts': True}
  query_terms = 'to:ceo@solarmora.com'
  mail_query = {
      'corpus': 'MAIL',
      'dataScope': 'HELD_DATA',
      'searchMethod': 'ACCOUNT',
      'accountInfo': {
          'emails': emails_to_search
      },
      'terms': query_terms,
      'mailOptions': mail_query_options,
  }
  mail_export_options = {
      'exportFormat': 'MBOX',
      'showConfidentialModeContent': True
      }
  wanted_export = {
      'name': 'My first mail accounts export',
      'query': mail_query,
      'exportOptions': {
          'mailOptions': mail_export_options
  }
}
return service.matters().exports().create(
  matterId=matter_id, body=wanted_export).execute()

Đối với các tệp xuất Gmail, các tệp xuất ở định dạng MBOX xử lý nhanh hơn các tệp xuất ở định dạng PST.

Tạo tệp xuất Drive

Ví dụ sau đây cho thấy cách tạo tệp xuất Drive. Yêu cầu này xuất tất cả các tệp, bao gồm cả các tệp trong bộ nhớ dùng chung, đáp ứng các tiêu chí sau:

  • Thuộc về đơn vị tổ chức được chỉ định (lấy được bằng Admin SDK).
  • Được tạo trong khoảng thời gian được chỉ định times.

Java

public Export createDriveOuAllDataExport(Vault client, String matterId) {
  OrgUnitInfo ouToSearch = new OrgUnitInfo().setOrgUnitId("ou id retrieved from admin sdk");
  DriveOptions driveQueryOptions = new DriveOptions().setIncludeSharedDrives(true);
  Query driveQuery =
      new Query()
          .setCorpus("DRIVE")
          .setDataScope("ALL_DATA")
          .setSearchMethod("ORG_UNIT")
          .setOrgUnitInfo(ouToSearch)
          .setDriveOptions(driveQueryOptions)
          .setStartTime("2017-03-16T00:00:00Z")
          .setEndTime("2017-03-16T00:00:00Z")
          .setTimeZone("Etc/GMT+2");
  DriveExportOptions driveExportOptions = new DriveExportOptions().setIncludeAccessInfo(false);
  Export wantedExport =
      new Export()
          .setName("My first drive ou export")
          .setQuery(driveQuery)
          .setExportOptions(new ExportOptions().setDriveOptions(driveExportOptions));
  return client.matters().exports().create(matter, wantedExport).execute();
}

Python

def create_drive_ou_all_data_export(service, matter_id):
  ou_to_search = 'ou id retrieved from admin sdk'
  drive_query_options = {'includeSharedDrives': True}
  drive_query = {
    'corpus': 'DRIVE',
    'dataScope': 'ALL_DATA',
    'searchMethod': 'ORG_UNIT',
    'orgUnitInfo': {
        'org_unit_id': ou_to_search
    },
    'driveOptions': drive_query_options,
    'startTime': '2017-03-16T00:00:00Z',
    'endTime': '2017-09-23T00:00:00Z',
    'timeZone': 'Etc/GMT+2'
  }
  drive_export_options = {'includeAccessInfo': False}
  wanted_export = {
    'name': 'My first drive ou export',
    'query': drive_query,
    'exportOptions': {
        'driveOptions': drive_export_options
    }
  }
return service.matters().exports().create(
  matterId=matter_id, body=wanted_export).execute()

Tạo tệp xuất Meet

Ví dụ sau đây cho thấy cách tạo tệp xuất Meet. Yêu cầu này xuất các tệp được liên kết với các tài khoản trong đơn vị tổ chức được chỉ định có tên tệp tuân theo mẫu cho bản ghi trên Meet.

Python

def create_meet_export(service, matter_id, ou_to_search, export_name):
  export = {
    'name': export_name,
    'query': {
        'corpus': 'DRIVE',
        'dataScope': 'ALL_DATA',
        'searchMethod': 'ORG_UNIT',
        'terms': 'title:"...-...-... \\(....-..-.. at ..:.. *\\)"',
        'orgUnitInfo': {
            'orgUnitId': 'id:'+ou_to_search
        },
        'driveOptions': {
            'includeTeamDrives': True,
            'includeSharedDrives': True
        },
        'timeZone': 'Etc/GMT',
        'method': 'ORG_UNIT'
    },
    'exportOptions': {
        'driveOptions': {},
        'region': 'ANY'
    },
  }

  return service.matters().exports().create(
    matterId=matter_id, body=export).execute()

Xuất từ một truy vấn đã lưu

Ví dụ sau đây cho thấy cách tạo tệp xuất từ một truy vấn đã lưu.

Python

def create_mail_export_from_saved_query(service, matter_id, saved_query_id, export_name):
  export = {
    'name': export_name,
    'exportOptions': {
      'mailOptions': {
        'exportFormat': 'PST',
        'showConfidentialModeContent': True
      },
    'region': 'ANY'
    }
  }

  export['query'] = service.matters().savedQueries().get(
    savedQueryId=saved_query_id, matterId=matter_id).execute()['query']
  return service.matters().exports().create(
    matterId=matter_id, body=export).execute()

Liệt kê tệp xuất

Ví dụ sau đây cho thấy cách truy xuất danh sách các tệp xuất được liên kết với một vụ việc.

Java

public class exports {
  public ListExportsResponse listExports(Vault client, String matterId) {
    return client.matters().exports().list(matterId).execute();
}

Python

def list_exports(service, matter_id):
 return service.matters().exports().list(matterId=matter_id).execute()

Xem thông tin về một tệp xuất

Ví dụ sau đây cho thấy cách xem thông tin về một tệp xuất cụ thể. Để tải các tệp và tin nhắn đã xuất xuống, bạn sử dụng Cloud API (trong ví dụ tiếp theo).

Java

public Export getExportById(Vault client, String matterId, String exportId) {
  return client.matters().exports().get(matterId, exportId).execute();
}

Python

def get_export_by_id(service, matter_id, export_id):
  return service.matters().exports().get(
    matterId=matter_id, exportId=export_id).execute()

Tải một tệp xuất xuống từ Google Cloud

Ví dụ sau đây cho thấy cách tải tất cả các tệp xuất đã hoàn tất trong một vụ việc xuống từ Google Cloud. Yêu cầu này sử dụng Vault và Cloud API.

Để tải một tệp xuất xuống, một tài khoản cần có đặc quyền Quản lý tệp xuất và được chia sẻ vụ việc đó.

Python

def download_exports(service, matter_id):
"""Google Cloud storage service is authenticated by running
`gcloud auth application-default login` and expects a billing enabled project
in ENV variable `GOOGLE_CLOUD_PROJECT` """
gcpClient = storage.Client()
matter_id = os.environ['MATTERID']
  for export in vaultService.matters().exports().list(
      matterId=matter_id).execute()['exports']:
    if 'cloudStorageSink' in export:
      directory = export['name']
      if not os.path.exists(directory):
        os.makedirs(directory)
      print(export['id'])
      for sinkFile in export['cloudStorageSink']['files']:
        filename = '%s/%s' % (directory, sinkFile['objectName'].split('/')[-1])
        objectURI = 'gs://%s/%s' % (sinkFile['bucketName'],
                                    sinkFile['objectName'])
        print('get %s to %s' % (objectURI, filename))
        gcpClient.download_blob_to_file(objectURI, open(filename, 'wb+'))

Xoá tệp xuất

Ví dụ sau đây cho thấy cách xoá một tệp xuất.

Java

public void deleteExportById(Vault client, String matterId, String exportId) {
   client.matters().exports().delete(matterId, exportId).execute();

Python

def delete_export_by_id(service, matter_id, export_id):
  return service.matters().exports().delete(
    matterId=matter_id, exportId=export_id).execute()

Để biết thông tin dành riêng cho ứng dụng về tính năng tìm kiếm và xuất, bao gồm cả hạn mức tìm kiếm, hãy xem Bắt đầu sử dụng tính năng tìm kiếm và xuất của Vault.