Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
a97ae3f
Update --search-depth param to work without recursive on
rushton Jul 1, 2015
4990dbe
experimental routine'd list work
rushton Jul 2, 2015
46f1d77
add recursive version
rushton Jul 4, 2015
7816fe1
fix issue with -r no longer working
rushton Jul 4, 2015
c74e247
add comment for recursive list function
rushton Jul 5, 2015
8a9795a
Remove useless middle-man processing code
rushton Jul 8, 2015
9030941
Go routines for print statements
rushton Jul 8, 2015
1dd6ee6
use bufio to output
rushton Jul 8, 2015
549ed78
use a single writer
rushton Jul 8, 2015
583de8c
don't use threads to write
rushton Jul 8, 2015
7b04b9e
increase buffer size
rushton Jul 8, 2015
87d4247
pass logger to main functions instead of using fmt.Print
rushton Jul 8, 2015
f4c2c4e
better function names
rushton Jul 8, 2015
e039cce
update docs
rushton Jul 8, 2015
de29b43
Merge pull request #3 from TuneOSS/cut_out_the_middleman
rushton Jul 15, 2015
f07c14d
add key regex filter for get function
rushton Jul 15, 2015
4bbf1f2
update readme
rushton Jul 15, 2015
d05dca1
Add bash and zsh completion scripts
rushton Jul 16, 2015
f081a1f
do not add space after completion
rushton Jul 16, 2015
6937e37
fix case where prefix is ""
rushton Jul 16, 2015
422f1af
add empty prefix check for Get func
rushton Jul 16, 2015
2a2f5dc
add .gzip extension as valid gzip extension
rushton Jul 24, 2015
d81ea1f
default to plain reader if gzip reader fails
rushton Jul 29, 2015
7ed34f3
move streaming functionality to s3 wrapper
rushton Jul 29, 2015
89f89ec
add Makefile
rushton Jul 30, 2015
87f5355
have s3wrapper.GetStream use GetReader instead of Get
rushton Jul 31, 2015
6822d98
user faster gzip library
rushton Aug 21, 2015
ae278c1
Merge pull request #5 from TuneOSS/faster_gzip
rushton Aug 21, 2015
317e05c
use correct import path for gzip library
rushton Aug 21, 2015
584624e
move common functions to a util package
rushton Aug 24, 2015
857b56e
added example for object sizes
hasjohnb Dec 7, 2015
4893183
Merge pull request #6 from hasjohnb/master
rushton Dec 7, 2015
8dc95b2
use rsync instead of cp --parent as it is compatible with BSD
rushton May 6, 2016
8a4bf3a
Version 1.1.0
rushton Jun 13, 2016
c7b2513
Merge pull request #8 from TuneOSS/v1.1.0
rushton Jun 13, 2016
f18049e
use kingpin v2 instead of kingpin v1
rushton Jun 13, 2016
e50ccce
Merge branch 'master' of github.com:TuneOSS/fasts3
rushton Jun 13, 2016
6557f87
look in current directory for binary when installing
rushton Jun 13, 2016
c0e5499
update readme about configuration
rushton Jun 13, 2016
7923904
only print FullKey when printing prefix directories
rushton Jun 13, 2016
082f11c
remove references to fasts3v2
rushton Jun 13, 2016
5926be1
remove awswrapper as it's no longer used
rushton Jun 13, 2016
4b5c90d
move file descriptor lock into go routine for streaming otherwise it
rushton Jun 13, 2016
63b329d
update installation instructions in README
rushton Jun 13, 2016
44fb7eb
actually implement includeKeyName on stream
rushton Jun 14, 2016
4506f78
update list of prefixes to avoid channel block
rushton Jun 24, 2016
b5f625a
base concurrency limits on number of CPUs instead of file descriptors
rushton Jun 24, 2016
ddff314
add missing dependencies
rushton Jun 25, 2016
9c4d8e8
simplify README
rushton Jun 25, 2016
1ce7e56
added cp command
hasjohnb Jul 10, 2016
2fb90aa
cleanup control flows
hasjohnb Jul 10, 2016
0f9f1dc
fix TODOs
hasjohnb Jul 10, 2016
0a85cab
merge from cp
hasjohnb Jul 10, 2016
f2620f5
fix flag name
hasjohnb Jul 11, 2016
391b120
default concurrency limit to 4*NumCPU()
hasjohnb Jul 11, 2016
e1cb136
merged GOMAXPROCS configuration, updated README
hasjohnb Jul 11, 2016
fe896d6
Merge pull request #9 from hasjohnb/cp
rushton Jul 12, 2016
e4f9010
Merge branch 'master' of github.com:TuneOSS/fasts3 into struct
hasjohnb Jul 12, 2016
2eaa626
remove superfluous 'env' from documentation
hasjohnb Jul 12, 2016
3e93ac6
Merge pull request #10 from hasjohnb/struct
rushton Jul 12, 2016
a784b02
bump to version 1.2.1
rushton Jul 12, 2016
a08df91
Merge pull request #11 from TuneOSS/bump_version
rushton Jul 12, 2016
2a0cb51
Add autocomplete demo
rushton Jul 13, 2016
5b846c6
add newline after demo
rushton Jul 13, 2016
6ae882b
Merge pull request #12 from TuneOSS/autocomplete_demo
rushton Jul 14, 2016
b009d89
Fix hard coded delmiter logic when searching depths
rushton Jul 15, 2016
86d50ad
version bump
rushton Jul 15, 2016
a6479ca
Merge pull request #13 from TuneOSS/hardcoded_delimiter
rushton Jul 15, 2016
476ca16
Make stream function non-blocking
rushton Aug 3, 2016
e4564a6
increment the minor version
rushton Aug 3, 2016
a12b8bf
move reader.Close below error checking
rushton Aug 3, 2016
9162ca8
Merge pull request #14 from TuneOSS/non_blocking_stream
rushton Aug 4, 2016
e64390b
Add support for listing buckets from Ls
Sep 14, 2016
eac6712
bump version to 1.2.4
Sep 14, 2016
e8df87a
code review updates
Sep 14, 2016
632ab92
use strings.HasPrefix in favor of regexp
Sep 14, 2016
313abb5
ensure s3Uris is a required parameter on the CLI
Sep 14, 2016
534e103
Merge pull request #17 from TuneOSS/listable_buckets
rushton Sep 15, 2016
9bfc53d
update to aws-sdk-go v1.4.9
Sep 15, 2016
390dd3f
bump version to 1.2.5
Sep 15, 2016
847dfe5
Merge pull request #18 from TuneOSS/update_aws_sdk
hasjohnb Sep 15, 2016
1274354
enable region config value in ~/.aws/credentials
Sep 15, 2016
3a80f53
remove debugging statement
Sep 15, 2016
e21b5b7
Merge pull request #19 from TuneOSS/use_proper_credentials
hasjohnb Sep 15, 2016
e6bc926
filter buckets which can't be listed on because of region constraints
Sep 15, 2016
cb32198
bump version to 1.2.7
Sep 15, 2016
722ad5e
Merge pull request #20 from TuneOSS/filter_location_constrained_buckets
hasjohnb Sep 15, 2016
ebff36f
add skip existing flag
Sep 16, 2016
2f575b2
Merge pull request #21 from TuneOSS/skip_existing
hasjohnb Sep 16, 2016
972ccb8
Remove makefile
Sep 23, 2016
828394c
use govendor instead of godep
hasTyler Sep 23, 2016
8665c40
remove make references in readme
hasTyler Sep 23, 2016
971f88f
Merge pull request #23 from hasTyler/master
rushton Sep 23, 2016
865d71a
Merge pull request #24 from hasTyler/migrateGovendor
rushton Sep 23, 2016
76c9e98
add documentation about region configuration
Sep 23, 2016
cdee4e9
consistent documentation
Sep 23, 2016
8a94400
add regex option for ls command
hasjohnb Oct 3, 2016
0670bf7
Merge pull request #26 from hasjohnb/master
rushton Oct 3, 2016
324fe7f
Add commentary about binary install location
hasTyler Oct 4, 2016
b746fea
Merge pull request #27 from hasTyler/master
rushton Oct 4, 2016
542c5e3
Merge pull request #25 from TuneOSS/add_region_doc
rushton Oct 7, 2016
1e1f584
Added rm functionality for deleting keys from S3
Oct 10, 2016
839b010
increment version number
Oct 10, 2016
8360232
add comments
Oct 10, 2016
90054a6
add constant for maximum number of keys per delete objects request
Oct 10, 2016
6764550
switch constant to camel-case and fix places where constant was not
Oct 10, 2016
77b6a35
fix bad(reverse) logic for filtering prefix
Oct 10, 2016
d560e9f
Merge pull request #28 from TuneOSS/rm
rushton Oct 11, 2016
a7ee210
increment minor version as we have added a new feature (rm)
Oct 11, 2016
2cd293d
Merge pull request #29 from TuneOSS/inc_minor_version
rushton Nov 16, 2016
e955563
increase "rm" operation concurrency
Jan 6, 2017
1426ea1
add wait group to close channel for rm function
Jan 6, 2017
94b2d72
version bump to 1.3.1
Jan 6, 2017
f4a950b
Merge pull request #31 from TuneOSS/increase_rm_concurrency
hasjohnb Jan 6, 2017
4f72c3a
Unescape S3 keys
Mar 16, 2017
08ccd32
increment minor version
Mar 16, 2017
ac7ad8b
allow output from stream to be raw and ordered. Using Raw bypasses
Nov 21, 2017
4c20620
inc the version
Nov 21, 2017
c53d3d6
use ReadBytes('\n') instead of ReadLine() as it is suggested in the
Nov 21, 2017
3c05cc0
Merge remote-tracking branch 'remotes/origin/unescape_s3_keys' into r…
Nov 22, 2017
a50325a
code review changes
Nov 28, 2017
6fadf15
Merge pull request #33 from TuneOSS/raw_ordered_streaming
rushton Nov 28, 2017
3e761ba
Update readme to properly format headers when rendered as markdown
zaquestion Nov 28, 2017
cc7a616
Merge pull request #34 from zaquestion/readme_formatting
rushton Nov 28, 2017
2222c40
TuneOSS -> tuneinc
Dec 22, 2017
65cecaf
inc version
Dec 22, 2017
c637058
Merge pull request #35 from tuneinc/tune_oss_to_tune_inc
zaquestion Jan 19, 2018
3892771
(ci) add travis config + badge, also goreportcard badge
zaquestion Jan 19, 2018
18a5262
Add MIT license
zaquestion Jan 19, 2018
a3785f3
run gofmt -s
zaquestion Jan 19, 2018
50be974
Merge pull request #36 from zaquestion/travis
rushton Jan 22, 2018
d6ae166
Merge pull request #37 from tuneinc/mit_license
rushton Jan 22, 2018
afed105
(readme) add trailing white space to force image onto next line
zaquestion Feb 2, 2018
3e09acd
Merge pull request #38 from zaquestion/badge_newline
rushton Feb 9, 2018
62b11f0
readme.md: move gif to the top
zaquestion Apr 21, 2018
d8ba74f
Merge pull request #39 from tuneinc/relocate-gif
rushton Apr 24, 2018
a91ff8d
removing unnecessary else
May 10, 2018
7883218
[adhoc:fasts3] add .gitignore and update if/else antipattern
May 10, 2018
a2cd5fa
remove naked return
May 10, 2018
223059e
Merge pull request #41 from zrivest/fix_if_else_antipattern
zaquestion May 10, 2018
658c2e9
Merge pull request #40 from salmic/go-workshop
zaquestion May 10, 2018
eac8eb4
Merge pull request #42 from bmacurdy/naked-return
zaquestion May 10, 2018
dd337bc
fix lint problems
May 10, 2018
87570ca
Remove the 'util' package.
HasMatthew May 10, 2018
dcff175
add missing dependency and increment minor version
May 10, 2018
78b5594
Merge remote-tracking branch 'matt/remove_util_pkg' into lint
May 10, 2018
2b04d90
fix more linting issues after merge
May 10, 2018
34cd290
Merge pull request #44 from HasMatthew/remove_util_pkg
zaquestion May 10, 2018
6a3288f
Merge pull request #43 from tuneinc/lint
rushton May 10, 2018
4e2ee95
Replace GOMAXPROCS/NumCPU-based parallelism limit with CLI flag.
HasMatthew Jun 7, 2018
619144c
Remove unnecessary pointers
hasDiana Jun 7, 2018
5c09c40
Merge pull request #45 from HasMatthew/parallel_flag
rushton Jun 7, 2018
6ca4eb4
Merge pull request #46 from hasDiana/REMOVE-POINTERS
zaquestion Jun 7, 2018
b4e16c9
increment version to 1.3.5
Jun 7, 2018
abd6d35
replace panics with more user-friendly error messages
Jun 7, 2018
79bcd72
Merge pull request #48 from tuneinc/no_panic
rushton Jun 7, 2018
98d2dd6
hookup goreleaser to manage releases
tunezaq Jun 7, 2018
f4dfe8c
Merge pull request #47 from zaquestion/goreleaser
zaquestion Jun 7, 2018
2eb88e1
update installation instructions
Jun 11, 2018
cd08dfc
Merge pull request #49 from tuneinc/update_install_instructions
zaquestion Jun 11, 2018
be4f44d
Recreate tool as cobra project, implement ls command, and convert to dep
zaquestion Jun 19, 2018
885668f
Add rm as cobra command
lelandbatey Jun 28, 2018
7393ccb
(cp command) filled out new cp command.
Jun 28, 2018
692706c
Rewrite the 'stream' command as a Cobra CLI command.
HasMatthew Jun 28, 2018
d5878eb
Update s3 get to cobra
adamryman Jun 28, 2018
476e4d7
Merge pull request #54 from HasMatthew/stream_cobra
zaquestion Jun 29, 2018
faedf08
Merge pull request #53 from salmic/cobra
zaquestion Jun 29, 2018
3a2cafe
Merge pull request #52 from lelandbatey/rm-cobra-cmd
zaquestion Jun 29, 2018
64e000f
Merge pull request #51 from adamryman/cobra_get
zaquestion Jun 29, 2018
92b4a8d
cobra conversion finishing touches, validate s3uris, remove old_main
zaquestion Jun 29, 2018
13898f8
display help if no child command was provided
Jul 18, 2018
8309e92
Merge branch 'cobra' of github.com:tuneinc/fasts3 into cobra
Jul 18, 2018
ac82986
simplify implementation of help on empty child command
Jul 18, 2018
5f419f4
Merge pull request #55 from tuneinc/cobra
rushton Jul 18, 2018
3a92ae4
update aws sdk
Jul 3, 2019
435f64c
Auto detect region for certain commands
Jul 3, 2019
55132d7
dont fail hard if region is not detected automatically
Jul 3, 2019
3ffdee7
remove debug statement
Jul 3, 2019
c8d7595
Merge pull request #1 from metaverse/update_aws_sdk
rushton Jul 9, 2019
6d069fe
Merge pull request #2 from metaverse/auto_detect_region
rushton Jul 9, 2019
679934e
redo dep ensure for aws sdk
Jul 9, 2019
7707b25
only try deleting if there are objects to delete
Jul 19, 2019
4164bfa
add support for setting endpoint and enabling path-style requests
Sep 6, 2019
466e14e
Merge pull request #3 from metaverse/endpoint_path_style_support
rushton Sep 11, 2019
7214ecb
Move to go mod for managing dependencies
Apr 14, 2022
9826921
Update README installation
rushton Apr 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/*
fasts3
45 changes: 45 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
project_name: fasts3
release:
github:
owner: tuneinc
name: fasts3
name_template: '{{.Tag}}'
brew:
description: "Fast s3 utility is a faster version of s3cmd's ls, get, and cp functions ideal for buckets containing millions of keys."
homepage: "https://github.com/tuneinc/fasts3"
github:
owner: tuneinc
name: homebrew-tap
commit_author:
name: goreleaserbot
email: goreleaser@carlosbecker.com
install: bin.install "fasts3"
builds:
- goos:
- linux
- darwin
goarch:
- amd64
- "386"
main: main.go
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
binary: fasts3
archive:
format: tar.gz
name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{
.Arm }}{{ end }}'
snapshot:
name_template: SNAPSHOT-{{ .Commit }}
checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt'
changelog:
filters:
# commit messages matching the regexp listed here will be removed from
# the changelog
# Default is empty
exclude:
- '^\(docs\)'
- '^\(travis\)'
- '^\(coverage\)'
- '^\(tests?'
- '^Merge pull request'
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
language: go

go:
- 1.9.x
- 1.10.x
- master

stages:
- test
- name: deploy
if: tag IS present

jobs:
include:
- stage: test
script: go build ./...
- stage: deploy
go: 1.10.x
script: curl -sL https://git.io/goreleaser | bash

matrix:
allow_failures:
- go: master
fast_finish: true

env:
global:
secure: "Iby/cnnH2C7SmMJoLBT1khL/jfiNxpoZ2axHyEHSeiaoixS75vkKtyHrrcs8A+71fKgMLOq4w5VGbNfHtrUWt6Ny4IFWiNk6RYPnFu72Bzm6bKFb5xS0yGPQ0Yo1GHGlNwHeBi9gI+MUQ4EDoKj4CGvVL60ELcZIaJjnNvXWRGU="
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 TUNE, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
161 changes: 47 additions & 114 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,157 +1,90 @@
[![Build Status](https://travis-ci.org/tuneinc/fasts3.svg?branch=master)](https://travis-ci.org/tuneinc/fasts3) [![Go Report Card](https://goreportcard.com/badge/github.com/tuneinc/fasts3)](https://goreportcard.com/report/github.com/tuneinc/fasts3)
![FastS3](http://i.imgur.com/A42azaA.png)
---

Fast s3 utility is a faster version of s3cmd's ls and del functions ideal for listing and deleting buckets containing millions of keys.
Fast s3 utility is a faster version of s3cmd's ls, get, and cp functions ideal for buckets containing millions of keys.

#Installation
![autocomplete demo for zsh](autocomplete_demo.gif)

# Installation

```bash
go get github.com/TuneOSS/fasts3
cd $GOPATH/src/github.com/TuneOSS/fasts3
go build
go get -u github.com/metaverse/fasts3
```
This should install the binary under `$GOPATH/bin/`

#Configuration
# Configuration

use `fasts3 init` command which will create a template file in ~/.fs3cfg
Use `aws configure` command from the aws cli tool (https://aws.amazon.com/cli/) which will create the necessary config files in `~/.aws/credentials`.

add your region to your credentials file to support tab-completion of buckets:
```ini
[default]
access_key=<access_key>
secret_key=<secret_key>
aws_access_key_id=xxxx
aws_secret_access_key=xxxx
region=us-east-1
```

fill in the template file with your s3 credentials

alternatively you can set these environment variables:
Alternatively you can set these environment variables which will take precedence over the credentials file:
```bash
export AWS_ACCESS_KEY_ID=<access_key>
export AWS_SECRET_ACCESS_KEY=<secret_key>
export AWS_REGION=us-east-1
```

#Usage

```
usage: fasts3 <command> [<flags>] [<args> ...]

Multi-threaded s3 utility

Flags:
--help Show help.

Commands:
help [<command>]
Show help for a command.

ls [<flags>] <s3uri>
List s3 prefixes.

del [<flags>] [<prefixes>]
Delete s3 keys

get [<flags>] [<prefixes>]
Fetch files from s3

stream [<flags>] [<prefixes>]
Stream s3 files to stdout

init
Initialize .fs3cfg file in home directory

```

#####ls
```
usage: fasts3 [<flags>] ls [<flags>] <s3uri>

List s3 prefixes.

Flags:
--help Show help.
-r, --recursive Get all keys for this prefix.
--search-depth=0 search depth to search for work.
-H, --human-readable human readable key size.
-d, --with-date include the last modified date.

Args:
<s3uri> paritial s3 uri to list, ex: s3://mary/had/a/little/lamb/

```

#####del
```
usage: fasts3 [<flags>] del [<flags>] [<prefixes>]

Delete s3 keys

Flags:
--help Show help.
-r, --recursive Delete all keys with prefix
--search-depth=0 search depth to search for work.

Args:
[<prefixes>] 1 or more partial s3 uris to delete delimited by space

```

#####get
```
usage: fasts3 get [<flags>] [<prefixes>]

Fetch files from s3

Flags:
--search-depth=0 search depth to search for work.

Args:
[<prefixes>] list of prefixes or s3Uris to retrieve
# Usage
Use:
```

#####stream
```
usage: fasts3 stream [<flags>] [<prefixes>]

Stream s3 files to stdout

Flags:
--search-depth=0 search depth to search for work.
--key-regex=KEY-REGEX
regex filter for keys

Args:
[<prefixes>] list of prefixes or s3Uris to retrieve
fasts3 --help
fasts3 <cmd> --help
```

####Using search depth to *go* faster
Many times you know the structure of your s3 bucket, this can be used to optimize listings. Say you have a structure like so:
### Using search depth to *go* faster
Many times you know the structure of your s3 bucket, and this can be used to optimize listings. Say you have a structure like so:
```bash
fasts3 ls s3://mybuck/logs/

DIR s3://mybuck/logs/2010/
DIR s3://mybuck/logs/2011/
DIR s3://mybuck/logs/2012/
DIR s3://mybuck/logs/2013/
DIR s3://mybuck/logs/2014/
DIR s3://mybuck/logs/2015/
```

doing a `fasts3 ls -r s3://mybuck/logs/` will read all keys under `logs` sequentially. We can make this faster by adding a `--search-depth 1` flag to the command which gives each of the underlying directories it's own thread increasing throughput.
Doing a `fasts3 ls -r s3://mybuck/logs/` will read all keys under `logs` sequentially. We can make this faster by adding a `--search-depth 1` flag to the command which gives each of the underlying directories its own thread, increasing throughput.

### Concurrency
The concurrency level of s3 command execution can be tweaked based on your usage needs. By default, `4*NumCPU` s3 commands will be executed concurrently, which is ideal based on our benchmarks. If you want to override this value, set `GOMAXPROCS` in your environment to set the concurrency level: `GOMAXPROCS=64 fasts3 ls -r s3://mybuck/logs/` will execute 64 s3 commands concurrently.

####Examples
### Examples
```bash
# ls
fasts3 ls s3://mybucket/ # lists top level directories and keys
fasts3 ls -r s3://mybucket/ # lists all keys in the bucket
fasts3 ls -r --search-depth 1 s3://mybucket/ # lists all keys in the bucket using the directories 1 level down to thread
fasts3 ls -r s3://mybucket/ | awk '{s += $1}END{print s}' # sum sizes of all objects in the bucket

# del
fasts3 del -r s3://mybuck/logs/ # deletes all keys in the prefix
fasts3 del s3://mybuck/logs/2015/01/12/api.log.201501122359.gz # deletes single key
fasts3 del $(fasts3 ls s3://mybuck/logs/2015/01/12 | awk -F " " '/api.log/{print $2}') # delete all keys that have "api.log" in them

#get
# get
fasts3 get s3://mybuck/logs/ # fetches all logs in the prefix

# stream
fasts3 stream s3://mybuck/logs/ # streams all logs under prefix to stdout
fasts3 stream --key-filter ".*2015-01-01" s3://mybuck/logs/ # streams all logs with 2015-01-01 in the key name stdout
fasts3 stream --key-regex ".*2015-01-01" s3://mybuck/logs/ # streams all logs with 2015-01-01 in the key name stdout

# cp
fasts3 cp -r s3://mybuck/logs/ s3://otherbuck/ # copies all subdirectories to another bucket
fasts3 cp -r -f s3://mybuck/logs/ s3://otherbuck/all-logs/ # copies all source files into the same destination directory
```

### Completion
Bash and ZSH completion are available.

To install for bash:
```
source completion.sh
```

For zsh:
```
source completion.zsh
```
Binary file added autocomplete_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 0 additions & 33 deletions awswrapper/aws.go

This file was deleted.

60 changes: 60 additions & 0 deletions cmd/cp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package cmd

import (
"fmt"
"log"
"strings"

"github.com/aws/aws-sdk-go/service/s3"
"github.com/spf13/cobra"
"github.com/metaverse/fasts3/s3wrapper"
)

// cpCmd represents the cp command
var cpCmd = &cobra.Command{
Use: "cp <src> <dest>",
Short: "Copy files within S3",
Long: ``,
Args: validateS3URIs(cobra.ExactArgs(2)),
Run: func(cmd *cobra.Command, args []string) {
recursive, err := cmd.Flags().GetBool("recursive")
if err != nil {
log.Fatal(err)
}
flat, err := cmd.Flags().GetBool("flat")
if err != nil {
log.Fatal(err)
}
err = Cp(s3Client, args, recursive, delimiter, searchDepth, keyRegex, flat)
if err != nil {
log.Fatal(err)
}
},
}

// Cp copies files from one s3 location to another using svc, s3Uris is a list of source and dest s3 URIs, recurse tells
// whether to list all keys under the source prefix, delimiter tells the delimiter to use when listing, searchDepth determines
// the number of prefixes to list before parallelizing list calls, keyRegex is a regex filter on keys, when flat is
// true it only takes the last part of the prefix as the filename.
func Cp(svc *s3.S3, s3Uris []string, recurse bool, delimiter string, searchDepth int, keyRegex string, flat bool) error {
listCh, err := Ls(svc, []string{s3Uris[0]}, recurse, delimiter, searchDepth, keyRegex)
if err != nil {
return err
}

wrap := s3wrapper.New(svc, maxParallel)

copiedFiles := wrap.CopyAll(listCh, s3Uris[0], s3Uris[1], delimiter, recurse, flat)
for file := range copiedFiles {
fmt.Printf("Copied %s -> %s%s%s\n", file.FullKey, strings.TrimRight(s3Uris[1], delimiter), delimiter, file.Key)
}

return nil
}

func init() {
rootCmd.AddCommand(cpCmd)

cpCmd.Flags().BoolP("recursive", "r", false, "Copy all keys for this prefix.")
cpCmd.Flags().BoolP("flat", "f", false, "Copy all source files into a flat destination folder (vs. corresponding subfolders)")
}
Loading