[英]Script to save files from Mac (iCloud) to S3 bucket (AWS)
So i guess first we need to write a script to save all the files from my iCloud which I guess we would have to do an API call for that?所以我想首先我们需要编写一个脚本来保存我的 iCloud 中的所有文件,我想我们必须为此调用 API? Then backup those files onto my aws S3 bucket.
然后将这些文件备份到我的 aws S3 存储桶中。 Then the next question is, do I have to manually run the script or can we automate the runtime of the script to go off every hour.
那么下一个问题是,我是否必须手动运行脚本,或者我们能否将脚本的运行时间自动化到每小时 go。
Thanks!谢谢!
If you don't mind, you can use a python script to do a combination of the ff:如果你不介意,你可以使用 python 脚本来组合 ff:
pyicloud
- To interact with your iCloud services and download your files locally. pyicloud
- 与您的 iCloud 服务交互并在本地下载您的文件。from pyicloud import PyiCloudService
api = PyiCloudService('jappleseed@apple.com', 'password')
# Some more setup if you have two-factor (or two-step) authentication
api.files.dir()
# Download the files you want locally, you can also open up a file stream if needed
boto3
- To interact with S3 service configured in your AWS account and upload (or backup) the files to your bucket. boto3
- 与您的 AWS 帐户中配置的 S3 服务交互并将文件上传(或备份)到您的存储桶。import boto3
client = boto3.client(
's3',
aws_access_key_id=os.getenv('AWS_ACCESS_KEY_ID'),
aws_secret_access_key=os.getenv('AWS_SECRET_ACCESS_KEY')
)
# Loop over your local files to back them up to S3
response = client.upload_file(local_filename, bucket_name, s3_filename)
cron job
to schedule your script to run daily if you want to be the one to manage the box where it will run.cron job
来安排您的脚本每天运行。 An alternative here is to build a more Cloud-native solution which is to place your entire python code on a Lambda function
that will be triggered by CloudWatch event
which will be scheduled daily.Lambda function
上,该代码将由每天安排的CloudWatch event
触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.