S3cmd

S3cmd is a command-line tool for uploading, retrieving, and managing data in cloud storage service providers that use the S3 protocol such as DreamObjects. It is ideal for scripts, automated backups triggered from cron, and so on.

The following instructions help you install and configure s3cmd to work with DreamObjects.

Installing S3cmd

These instructions were performed with s3cmd v2.0.0. If you’d like to install a different version, you’ll need to modify the file names appropriately.

  1. Log in to your server via SSH.

    [server]$ mkdir ~/bin
  2. Create a bin directory in your home directory if you don’t have one already.

    [server]$ curl -O -L https://github.com/s3tools/s3cmd/archive/v2.0.0.tar.gz
  3. Download the latest release of s3cmd from GitHub.

    [server]$ tar xzf v2.0.0.tar.gz
  4. Untar the file.

    [server]$ cd s3cmd-2.0.0
  5. You should now have a directory called s3cmd-2.0.0. Change into that directory
    [server]$ cp -R s3cmd S3 ~/bin
  6. Copy the s3cmd executable and S3 folder into the bin directory created earlier

    [server]$ echo "export PATH=$HOME/bin:$PATH" >> ~/.bash_profile
  7. Add the bin directory to your path so that you can execute the newly installed script.

    This assumes you’re using the default bash shell. If you’re using a different shell, you’ll have to set the path in the proper place.

    [server]$ . ~/.bash_profile
  8. Execute your bash profile for it to take effect

Configuring S3cmd

Instead of following the instructions on the s3cmd site to configure it, just do the following:

  1. Create a file in your home directory called .s3cfg (note the leading “dot”)
    [server]$ cd ~
    [server]$ touch .s3cfg
  2. Copy the content of the code block below into it.
    [default]
    access_key = Your_DreamObjects_Access_Key
    secret_key = Your_DreamObjects_Secret_Key
    host_base = objects-us-west-1.dream.io
    host_bucket = %(bucket)s.objects-us-west-1.dream.io
    enable_multipart = True
    multipart_chunk_size_mb = 15
    use_https = True
    
  3. Include your Access and Secret Key from the DreamObjects control panel.

Additional configuration settings

website_endpoint = %(bucket)s.objects-website-us-west-1.dream.io
verbosity = ERROR

Making a bucket

[server]$ s3cmd mb s3://s3cmd-justin
Bucket 's3://s3cmd-justin/' created

Listing all buckets

[server]$ s3cmd ls
2014-02-28 16:28  s3://s3cmd-justin

Uploading a file into a bucket

[server]$ s3cmd put testfile.txt s3://s3cmd-justin/
testfile.txt -> s3://s3cmd-justin/testfile.txt  [1 of 1]
127 of 127   100% in    0s  1522.87 B/s  done

Listing the contents of a bucket

[server]$ s3cmd ls s3://s3cmd-justin
2014-02-28 16:29       127   s3://s3cmd-justin/testfile.txt

Downloading a file from a bucket

[server]$ s3cmd get s3://s3cmd-justin/testfile.txt
s3://s3cmd-justin/testfile.txt -> ./testfile.txt  [1 of 1]
127 of 127   100% in    0s     3.46 kB/s  done

Deleting a file in a bucket

[server]$ s3cmd del s3://s3cmd-justin/testfile.txt
File s3://s3cmd-justin/testfile.txt deleted

Listing the size of a bucket

[server]$ s3cmd du -H s3://s3cmd-justin
40G      s3://s3cmd-justin

Recursively make every object in a bucket public

[server]$ s3cmd setacl s3://3cmd-justin --acl-public --recursive

Recursively make every object in a bucket private

[server]$ s3cmd setacl s3://3cmd-justin --acl-private --recursive

Disable Directory Listing in a bucket

[server]$ s3cmd setacl s3://3cmd-justin --acl-private

Work with multiple accounts

It’s possible to use different configuration files, one for each account on DreamObjects. By default s3cmd puts its configuration file in ~/.s3cfg, but you can override a configuration file with the -c option and specify a different configuration file.

[server]$ s3cmd -c .s3cfg-another-identity ls

For convenience, you can use aliases in the ~/.bash_profile file:

# s3cmd aliases for different s3 accounts
alias s3my='s3cmd -c ~/.s3cfg-main-identity'
alias s3alt='s3cmd -c ~/.s3cfg-another-identity'

Did this article answer your questions?

Article last updated .