Permalink
Browse files

--delete-after-fetch option added

  • Loading branch information...
1 parent 19a529a commit 552df705e60ddab3252053a53d16d31a31ffe5c5 @nicjansma nicjansma committed Dec 6, 2012
Showing with 8 additions and 0 deletions.
  1. +1 −0 S3/Config.py
  2. +7 −0 s3cmd
View
@@ -53,6 +53,7 @@ class Config(object):
#'acl', # Full ACL (not yet supported)
]
delete_removed = False
+ delete_after_fetch = False
_doc['delete_removed'] = "[sync] Remove remote S3 objects when local file has been deleted"
gpg_passphrase = ""
gpg_command = ""
View
7 s3cmd
@@ -448,6 +448,9 @@ def cmd_object_get(args):
speed_fmt = formatSize(response["speed"], human_readable = True, floating_point = True)
output(u"File %s saved as '%s' (%d bytes in %0.1f seconds, %0.2f %sB/s)" %
(uri, destination, response["size"], response["elapsed"], speed_fmt[0], speed_fmt[1]))
+ if Config().delete_after_fetch:
+ s3.object_delete(uri)
+ output(u"File %s removed after fetch" % (uri))
def cmd_object_del(args):
for uri_str in args:
@@ -791,6 +794,9 @@ def cmd_sync_remote2local(args):
output(u"File '%s' stored as '%s' (%d bytes in %0.1f seconds, %0.2f %sB/s) %s" %
(uri, unicodise(dst_file), response["size"], response["elapsed"], speed_fmt[0], speed_fmt[1],
seq_label))
+ if Config().delete_after_fetch:
+ s3.object_delete(uri)
+ output(u"File '%s' removed after syncing" % (uri))
total_size += response["size"]
total_elapsed = time.time() - timestamp_start
@@ -1499,6 +1505,7 @@ def main():
optparser.add_option( "--delete-removed", dest="delete_removed", action="store_true", help="Delete remote objects with no corresponding local file [sync]")
optparser.add_option( "--no-delete-removed", dest="delete_removed", action="store_false", help="Don't delete remote objects.")
+ optparser.add_option( "--delete-after-fetch", dest="delete_after_fetch", action="store_true", help="Delete remote objects after fetching to local file (only for [get] and [sync] commands).")
optparser.add_option("-p", "--preserve", dest="preserve_attrs", action="store_true", help="Preserve filesystem attributes (mode, ownership, timestamps). Default for [sync] command.")
optparser.add_option( "--no-preserve", dest="preserve_attrs", action="store_false", help="Don't store FS attributes")
optparser.add_option( "--exclude", dest="exclude", action="append", metavar="GLOB", help="Filenames and paths matching GLOB will be excluded from sync")

0 comments on commit 552df70

Please sign in to comment.