Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Hemanthdev/77c2d0d7b2325d2fe981df3bcf9bab78 to your computer and use it in GitHub Desktop.
Save Hemanthdev/77c2d0d7b2325d2fe981df3bcf9bab78 to your computer and use it in GitHub Desktop.

Revisions

  1. @ivangayton ivangayton created this gist Aug 15, 2018.
    37 changes: 37 additions & 0 deletions kobo-docker_to_digital_ocean_spaces.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    #!/bin/bash

    # From a cloud instance of Kobo-Docker, pull all of the attachments
    # and place them in a (much cheaper) Spaces filebin.
    # Assumes a Kobo-Docker instance running on a DO Ubuntu 16.04 instance


    # Need Amazon's CLI utility to manage transfers to/from spaces
    sudo apt install s3cmd

    # Add a key for the server in question to access your Spaces account:
    # https://www.digitalocean.com/docs/spaces/how-to/administrative-access/

    # copy the key and secret token, and run (on the cloud server):
    s3cmd --configure
    # https://www.digitalocean.com/docs/spaces/resources/s3cmd/
    # then you have to edit the config file at ~.s3cfg
    nano .s3cfg
    # Change host_base to appropriate example: nyc3.digitaloceanspaces.com
    # and host_bucket example: %(bucket)s.nyc3.digitaloceanspaces.com

    #Navigate to the folder containing the files
    cd kobo-docker/.vols/kobocat_media_uploads/$USER/attachments/

    # Run GNU Screen so that you can close your terminal window without
    # stopping all of the transfers in a moment
    screen

    # start the transfers
    for i in $(find . -name *.jpg); do s3cmd put $i s3://ivan-filebin/FOLDER/; done;
    # You can then shut down that terminal and it will continue working (because of Screen)

    # later, go back into the server and launch a permission change to make the images public
    nohup s3cmd setacl s3://ivan-filebin/FOLDER --acl-public --recursive &
    # Again, you can shut down your terminal without interrupting the process (because of nohup)
    # and you can see the progress by doing
    tail -f nohup.out