问题描述
我正在使用gsutil将数据从本地计算机文件加载到GCS。但是现在我想安排20分钟的时间间隔将数据从本地计算机导出到Google云存储。我们如何创建这种类型的cron作业在哪里创建?
解决方法
您应该在本地计算机上创建一个脚本来完成此任务。
它看起来像这样(确保您授予文件可执行权限):
#! /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 –e
编辑crontab文件并添加以下行:
*/20 * * * * [PATH-TO-SCRIPT]/[NAME-OF-SCRIPT].sh >/dev/null 2>&1