s3cmd icon indicating copy to clipboard operation
s3cmd copied to clipboard

delete local file after upload

Open telepath opened this issue 11 years ago • 27 comments

I'm looking for an easy way to move files to an s3 bucket. With rsync this would be achieved with --remove-source-files. Please consider adding this to s3cmd.

telepath avatar Jan 01 '14 10:01 telepath

+1 I could use this capability, too.

johnzachary avatar Sep 19 '14 13:09 johnzachary

+1, looks like this has also been requested here

joshenders avatar Dec 19 '14 01:12 joshenders

+1

micrub avatar Dec 19 '14 06:12 micrub

This is particularly abrasive as the put verb does not return > 0 on failure:

$ s3cmd put THIS_FILE_DOES_NOT_EXIST s3://MY_VALID_BUCKET/; echo $?
0

joshenders avatar Jan 13 '15 20:01 joshenders

For the record, [put] now returns a more valid exit code in this case.

$ ./s3cmd --version s3cmd version 1.5.0

$ ./s3cmd put THIS_FILE_DOES_NOT_EXIST s3://MY_VALID_BUCKET/; echo $? ERROR: Parameter problem: Nothing to upload. 64

On Tue, Jan 13, 2015 at 2:52 PM, Josh Enders [email protected] wrote:

This is particularly abrasive as the put verb does not return > 1 on failure:

$ s3cmd put THIS_FILE_DOES_NOT_EXIST s3://MY_VALID_BUCKET/; echo $? 0

— Reply to this email directly or view it on GitHub https://github.com/s3tools/s3cmd/issues/262#issuecomment-69817610.

mdomsch avatar Jan 13 '15 21:01 mdomsch

+1, this would be really helpful

ravdeep003 avatar Feb 23 '15 09:02 ravdeep003

+1

haimari avatar Mar 15 '15 12:03 haimari

+1 does anyone have a workaround solution now?

teohm avatar Apr 22 '15 07:04 teohm

+1

apeschel avatar Jun 17 '15 23:06 apeschel

+1

chellmann avatar Feb 14 '16 09:02 chellmann

Or just implement move command for local files like awscli.

s3cmd mv /var/log/mylog.log s3://my-bucket/logs/

peycho avatar May 25 '16 14:05 peycho

rclone.org also implements a 'move' command. Alas it doesn't really deal well with directories that contain more than a few files.

s3cmd copes with this perfectly, but it doesn't move local files and --delete-after only works with sync which doesn't help me much.

@mdomsch ; thank you for creating s3cmd! It has been a great help with deploying and testing our new setup! The new versions also work great with Ceph without the hostname based buckets.

BartVB avatar Jun 14 '16 14:06 BartVB

+1

lrehmann avatar Apr 06 '17 22:04 lrehmann

@BartVB s3cmd sync --delete-after does not delete local files after upload, but

delete destination files that are not found anymore at the source. The difference of this option compared to normal delete-removed is that files are deleted only once all files have been successfully uploaded instead of at the beginning before upload.

(from https://github.com/s3tools/s3cmd/issues/958)

frallain avatar Mar 01 '18 19:03 frallain

+1 for this feature (surprised it didn't exist) ... would like to sync logs from a jump host to S3 then clean jump host up once I know they are backed up

fryguy04 avatar May 29 '18 21:05 fryguy04

+1

soloradish avatar Jul 10 '18 09:07 soloradish

Four years later, +1 :smirk:

man logrotate

micrub avatar Jul 12 '18 00:07 micrub

+1

aberenshtein avatar Nov 08 '18 15:11 aberenshtein

+1

spooksie avatar Mar 26 '20 19:03 spooksie

+1

xxx44yyy avatar Jul 05 '20 17:07 xxx44yyy

+1

amanjuman avatar Oct 03 '20 11:10 amanjuman

+1

connoranderson avatar Nov 10 '20 01:11 connoranderson

7 years and count..

mrnonz avatar Feb 11 '21 04:02 mrnonz

+1

find /logs -type f | while read -r FILE; do
  s3cmd put "$FILE" s3://bucketname
  if [ $? -eq 0 ]; then
    echo "$FILE successfully uploaded at $(date +'%d-%m-%Y-%H-%M-%S')" >> s3cmd-$(date +'%d-%m-%Y').log
    rm -f "$FILE"
  else
    echo "$FILE ERROR: failed to upload file $FILE at $(date +'%d-%m-%Y-%H-%M-%S')" >> s3cmd-$(date +'%d-%m-%Y').log
    exit 1
  fi
done

vainkop avatar Feb 19 '21 10:02 vainkop

8 years +1

Azerothian avatar Aug 31 '22 01:08 Azerothian

I'll fix this for a 200$ bounty.

EnderKilledYou avatar Sep 10 '22 19:09 EnderKilledYou

ok to spare my inbox I have added the requested feature. I need someone with an s3 bucket to test them as I don't have a s3 bucket available but I should be able to fix any thing quickly.

Overview of changes:

Added delete_after_put config option that is loaded from config if delete_after_put is True, then after the put the loop will call os.unlink (not sure if it works on single upload -- need tester no s3)

Did it all in the new github editor need someone to make sure I didn't miss a tab.

The branch

I will take donations at [email protected]

EnderKilledYou avatar Sep 10 '22 19:09 EnderKilledYou