[英]Copy folder named today's date to AWS s3 using bash script and `date`
Im trying to have part of my script copy an entire folder daily to AWS.我试图让我的脚本的一部分每天将整个文件夹复制到 AWS。 No matter what I try, it seems to fail and tell me [Errno 21] Is a directory:
Script is super simple, but it will only copy (or sync) the contents of the folder and never the folder itself.不管我怎么尝试,似乎都失败了,告诉我[Errno 21] Is a directory:
脚本超级简单,但它只会复制(或同步)文件夹的内容,而不会复制文件夹本身。
#!/bin/bash
today2=`date +\%Y-\%m-\%d`
aws s3 sync /home/$today2 s3://testbucket/
Another script I use creates creates a folder with today's date and then pushes backups in to it.我使用的另一个脚本创建了一个包含今天日期的文件夹,然后将备份推送到其中。 I want to move that day's folder to AWS.我想将那天的文件夹移动到 AWS。 I've tried --recursive
tried using both aws s3 cp
and aws s3 sync
but neither of them seem to work.我试过--recursive
尝试同时使用aws s3 cp
和aws s3 sync
但它们似乎都不起作用。
If I was to just sync the root folder, it would copy over the folder that I needed, but I don't want all the other stuff in there... just today's folder.如果我只是同步根文件夹,它会复制我需要的文件夹,但我不想要那里的所有其他东西......只是今天的文件夹。 Thanks in advance for any ideas.提前感谢您的任何想法。
也许我没有考虑这一点,但是这个,但是为什么aws s3 sync /home/$today2 s3://testbucket/$today2
不起作用?
@Jamie Starke answer helped to solve my task with the Copy command @Jamie Starke 的回答帮助我使用 Copy 命令解决了我的任务
Works for me:为我工作:
#!/bin/sh
TODAYBKPDIR="$(date "+%Y-%m-%d")"
aws s3 cp --recursive /path/to/your/directory/"$TODAYBKPDIR" s3://your-bucket-name/"$TODAYBKPDIR"
I had a similar issue, other way around trying to copy a file from S3 to local folder with date in the file name, need to be done everyday and in my sh file i had the below code and it worked perfectly.我有一个类似的问题,试图将文件从 S3 复制到文件名中包含日期的本地文件夹,需要每天完成,在我的 sh 文件中,我有以下代码,它运行良好。
#!/bin/bash
today=$(date +%Y%m%d)
sudo aws s3 sync s3://<S3-PATH>/ /<my_local_folder>/A/ --exclude "*" --include "startup_sh.log."$today*
* is to copy all files created today.
hope this answer helps someone who needs both aws s3 and bash commands.希望这个答案对需要 aws s3 和 bash 命令的人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.