After copying files using gsutil, they are not deleted instantly from the local storage - cmd

My task is to upload CSV files from the local database to the Google Cloud storage.
To do this, I first copy them to my desktop and then upload them to the Google Cloud storage.
I want this to be done automatically, without my participation. Therefore, I created a CMD file that will be run by Task Scheduler. The structure of the CMD file is the next:
gsutil cp C:\Users\Myname\Desktop\test\*.csv gs://my-bucket
gsutil rm C:\Users\Myname\Desktop\test\*.csv
But after loading data into `Google Cloud storage, it does not delete the CSV files.
However, if you run the delete in a separate command, it successfully deletes files.
Just:
gsutil rm C:\Users\Myname\Desktop\test\*.csv
But I want the download and removal code to be in one file.
I also tried this way (but it did not help me either):
gsutil cp C:\Users\Myname\Desktop\test\*.csv gs://my-bucket
del C:\Users\Myname\Desktop\test\*.csv
What are the solutions to this problem?

The gsutil mv command is designed for this use case.
Note, however, the docs section about atomicity. Especially with moving from your local filesystem to the cloud, there is no way to upload and delete atomically, so the command will first upload, verify the file is stored in the cloud, and then delete the local file.

The problem is cause by gsutil being a script. On Windows, this script (gsutil) exits and stops further processing of commands in your batch file.
The solution is to add the word call in front of gsutil:
call gsutil cp C:\Users\Myname\Desktop\test\*.csv gs://my-bucket
Next, do not use gsutil to delete a local file. Use del instead.

Related

How to execute a bash file containing curl instructions within a Google storage bucket and directly copy the contents to the bucket?

I have a bash script file where each line is a curl command to download a file. This bash file is in a Google bucket.
I would like to execute the file either directly from the storage and copy its downloaded contents there or execute it locally and directly copy its content to the bucket.
Basically, I do not want to have these fils on my local machine.. I have tried things along these lines but it either failed or simply downloaded everything locally.
gsutil cp gs://bucket/my_file.sh - | bash gs://bucket/folder_to_copy_to/
Thank you!
To do so, the bucket needs to be mounted on the pod (the pod would see it as a directory).
If the bucket supports NFS, you would be able to mount it as shown here.
Also, there is another way as shown in this question.
otherwise, you would need to copy the script to the pod, run it, then upload the generated files to the bucket, and lastly clean everything up.
The better option is to use a filestore which can be easily mounted using CSI drivers as mentioned here.

Is there way to transfer all zip files from s3 bucket aws to other computer?

I have module where I need transfer all zip files from s3 bucket to my network computers by by just connecting each ip address \xx.xx.xx.xxx. right now im using laravel.
exec('aws s3 cp s3://compexp/"11-10-2019"/"01150exp.zip"');
I have bucket name: compexp inside of bucket, there are created folder name: example 11-10-2019 inside of of dated folder there are zip files for the reference see the imported image.
zip files
currently this is my reference, but i can't see how can i transfer the files from my network computers.
https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html
You can use flag --recursive together with --exclude "*" --include "*.zip" to copy only *.zip in folder "11-10-2019".
Regarding the network computers, Do you mean your internal network computers?
You can't pass another server as the destination to copy the contents. You need to copy the files locally first and the transfer to another server. A good way to sync a directory from S3 bucket contents is to use the sync command as mentioned here
aws s3 sync yourLocalDir s3://mybucket
Once you have all the contents synced up in your current directory you can just copy them to a different computer using scp command as mentioned here
scp -r yourLocalDir anotherHost:/directory
-r option of scp is to make sure you copy all the subdirectories recursively

Shell command for copying the contents of one folder to another

Due to the way the Plesk Extension on my web server works, I am trying to write a shell command that fires after a deployment. This simply needs to copy the contents of one folder to another.
Currently, I am using this:
cp -r /deployed-site/public/ /httpdocs/
However, this only seems to work if the destination folder is empty. Every time a deployment occurs, I want the contents of the first folder copied and pasted into the second?
I would say it's better to clean the destination folder before copying files:
rm -rf /httpdocs
cp -r /deployed-site/public/ /httpdocs/

aws s3 cp to a local file was not replacing file

I have a shell script that is running aws s3 cp s3://s3file /home/usr/localfile. The file already exists in that directory, so the cp command is essentially getting the latest copy from S3 to get the latest version.
However, I noticed today that the file was not the latest version; it didn't match the file on S3. Looking at the shell script's stdout from the last two runs, it looks like the command ran - the output is: download: s3://s3file to usr/localfile. But when I compared the copies, they didn't match. The changed timestamp on the file when I view it on the local machine via WinSCP (a file transfer client) didn't change either
I manually ran the command in a shell just now and it copied the file from S3 to the local machine and successfully got the latest copy.
Do I need to add a specific option for this, or is it typical behavior for files to not override a file after aws s3 cp?

s3cmd put -preserve flag does not preserve file creation /Modified date when copied to s3 bucket

I am copying files for AWS ec2 to AWS s3 bucket, with --preserver flag to preserver to file create and modified date, but once file is copied to s3bucket, "s3cmd ls s3://bucket-name/" command list the file upload time as file time, it does not preserve the original file creation date-time. I am using following command(s3cmd put --preserve xyz.log s3://bucket-name/) to copy the file. Though s3cmd help list the --preserve or -p as something you can use to preserve the date it does not seems to be working.
Has anybody run in to this kind of issue and can point me what I am doing wrong.
I also tried s3cmd sync but sync command also behave same way, though I would prefer to use put.
s3cmd put --preserve xyz.log s3://bucket-name/
Thanks,
Please try the current upstream github.com/s3tools/s3cmd master branch. This is resolved there. Going round trip (s3cmd sync --preserve file s3://bucket/; rm file; s3cmd sync --preserve s3://bucket/file .;) now restores the atime and mtime values as stored during sync upload.

Resources