Skip to content

Instantly share code, notes, and snippets.

@jbutko
Last active July 18, 2023 12:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jbutko/a00b6525b24fa276a3a3898dc4e43437 to your computer and use it in GitHub Desktop.
Save jbutko/a00b6525b24fa276a3a3898dc4e43437 to your computer and use it in GitHub Desktop.
Unix (ubuntu): setup and use s3cmd to upload files to digitalocean spaces

Setup s3cmd to upload to digitalocean spaces

Generate new spaces API keys

https://cloud.digitalocean.com/account/api/tokens

Install s3cmd

sudo apt-get install s3cmd

Configure s3cmd to use digitaocean spaces

https://docs.digitalocean.com/products/spaces/resources/s3cmd/

s3cmd --configure

Config example (/home/username/.s3cfg):

[default]
access_key = xyz
bucket_location = US
cloudfront_host = cloudfront.amazonaws.com
host_base = fra1.digitaloceanspaces.com
host_bucket = %(bucket)s.fra1.digitaloceanspaces.com
human_readable_sizes = True
simpledb_host = sdb.fra1.digitaloceanspaces.com
use_https = True
website_endpoint = http://%(bucket)s.s3-website-%(location)s.fra1.digitaloceanspaces.com/

Test it works

s3cmd ls

Upload file to folder

s3cmd put some.log s3://logs/server/

Upload multiple files

s3cmd put file1.txt file2.txt path/to/file3.txt s3://spacename/path/

Upload a file under a new name

s3cmd get s3://spacename/file.txt newfilename.txt

Put all files in your current directory

s3cmd put * s3://spacename/path/ --recursive

Get/download file

s3cmd get s3://logs/server/some.log

Download all files from dir

s3cmd get s3://spacename/path/ --recursive

Delete file

s3cmd rm s3://logs/server/some.log

Delete all files in folder

s3cmd rm s3://logs/server/ --recursive --force

Delete dir

s3cmd del s3://logs/server

Show disk usage

s3cmd du

Remove bucket (folder)

s3cmd del -f -r s3://newspace/ # purge all data first
s3cmd rb s3://newspace/ # destry bucket

Sync folder

s3cmd sync --dry-run --delete-removed --preserve ~/demo/ s3://s3tools-demo/some/path/

More commands: https://docs.digitalocean.com/products/spaces/resources/s3cmd-usage/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment