首页 > 解决方案 > 调度 gsutil 命令

问题描述

我正在使用 gsutil 将数据从本地机器文件加载到 GCS。但现在我想将它安排为 20 分钟间隔,数据将从本地机器导出到谷歌云存储。我们如何创建这种类型的 cron 作业以及应该在哪里创建我创造?

标签: google-cloud-platformschedulinggsutil

解决方案


您应该在本地计算机中创建一个脚本来完成此任务。

它可能看起来像这样(确保您授予文件可执行权限):

#! /bin/bash

PATH="$PATH":[REPLACE with /path/to/gsutil/]

# The ".boto" file contains the settings that helps you do operations with your bucket: https://cloud.google.com/storage/docs/boto-gsutil
export BOTO_CONFIG=[REPLACE with "/home/username/.boto"]

# upload the file with the relevant gsutil command
gsutil cp [Replace with OBJECT_LOCATION] gs://[REPLACE with DESTINATION_BUCKET_NAME]/

以下 cron 计划表达式:*/20 * * * *应该每 20 分钟触发一次作业,因此编辑 crontab 文件crontab –e并添加以下行:

*/20 * * * * [PATH-TO-SCRIPT]/[NAME-OF-SCRIPT].sh >/dev/null 2>&1

以下站点是您计算 cron 计划表达式的绝佳资源,是一个关于如何使用 linux 设置 cronjob 的非常好的教程。


推荐阅读