-
-
Save blalop/b2caf4ef3127240a2e91baaec58ec29f to your computer and use it in GitHub Desktop.
Archives, compresses, encrypts and uploads a folder to Dropbox. Document backup purpose.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
OAUTH_ACCESS_TOKEN=<YOUR OAUTH ACCESS TOKEN HERE> | |
PASSPHRASE=<YOUR PASSPHRASE> | |
archive_and_compress_folder() { | |
tar -czf "$1.tar.gz" "$1" | |
} | |
encrypt_file() { | |
gpg -c --batch --passphrase "$PASSPHRASE" "$1.tar.gz" &> /dev/null | |
} | |
upload_file() { | |
local authorization_header="Authorization: Bearer $OAUTH_ACCESS_TOKEN" | |
local dropbox_api_header="Dropbox-API-Arg: {\"path\": \"/$1\", \"mode\": \"overwrite\", \"mute\": true }" | |
local content_type_header="Content-Type: application/octet-stream" | |
curl -X POST https://content.dropboxapi.com/2/files/upload \ | |
--header "$authorization_header" \ | |
--header "$dropbox_api_header" \ | |
--header "$content_type_header" \ | |
--data-binary @"$1.tar.gz.gpg" | |
} | |
clean_up() { | |
rm -f "$1.tar.gz" "$1.tar.gz.gpg" | |
} | |
archive_and_compress_folder "$1" | |
encrypt_file "$1" | |
upload_file "$1" | |
clean_up "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment