From ead19ea382d32a2dd2d1ba17b37d838191532c78 Mon Sep 17 00:00:00 2001 From: Felix Bartels Date: Wed, 8 Apr 2015 07:34:04 +0200 Subject: [PATCH 1/4] also backup starred gists (in a simple hackish way) --- gist-backup | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gist-backup b/gist-backup index 9ed21d3..699f5d2 100755 --- a/gist-backup +++ b/gist-backup @@ -120,6 +120,34 @@ do retries=0 done +page=1 +retries=0 +MAX_RETRIES=5 +while [ $retries -lt $MAX_RETRIES ] +do + echo "Requesting Starred Gist page: $page" + + gists=$( + curl -s -H "Authorization: token $token" -d "page=$page" -G https://api.github.com/gists/starred | + sed -n 's/.*git_pull_url": "\(.*\)",/\1/p' + ) + + if [ -z "$gists" ] + then + echo "No starred gists found on this page. Trying again." + retries=$(( retries + 1 )) + continue + fi + + for gist in $gists + do + backup $gist + done + + page=$(( page + 1 )) + retries=0 +done + echo "No gists found (anymore). Not trying again." exit 0 From 1e912f6056b3976f08a71de7b535b00ad9729dd9 Mon Sep 17 00:00:00 2001 From: Felix Bartels Date: Wed, 8 Apr 2015 07:56:16 +0200 Subject: [PATCH 2/4] also backup starred gists in a less hackish way --- gist-backup | 75 ++++++++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 50 deletions(-) diff --git a/gist-backup b/gist-backup index 699f5d2..27c7f73 100755 --- a/gist-backup +++ b/gist-backup @@ -92,60 +92,35 @@ backup() { fi } -page=1 -retries=0 -MAX_RETRIES=5 -while [ $retries -lt $MAX_RETRIES ] +for url in https://api.github.com/gists https://api.github.com/gists/starred do - echo "Requesting Gist page: $page" - - gists=$( - curl -s -H "Authorization: token $token" -d "page=$page" -G https://api.github.com/gists | - sed -n 's/.*git_pull_url": "\(.*\)",/\1/p' - ) - - if [ -z "$gists" ] - then - echo "No gists found on this page. Trying again." - retries=$(( retries + 1 )) - continue - fi - - for gist in $gists - do - backup $gist - done - - page=$(( page + 1 )) + page=1 retries=0 -done - -page=1 -retries=0 -MAX_RETRIES=5 -while [ $retries -lt $MAX_RETRIES ] -do - echo "Requesting Starred Gist page: $page" - - gists=$( - curl -s -H "Authorization: token $token" -d "page=$page" -G https://api.github.com/gists/starred | - sed -n 's/.*git_pull_url": "\(.*\)",/\1/p' - ) - - if [ -z "$gists" ] - then - echo "No starred gists found on this page. Trying again." - retries=$(( retries + 1 )) - continue - fi - - for gist in $gists + MAX_RETRIES=5 + while [ $retries -lt $MAX_RETRIES ] do - backup $gist + echo "Requesting Gist page: $page from $url" + + gists=$( + curl -s -H "Authorization: token $token" -d "page=$page" -G $url | + sed -n 's/.*git_pull_url": "\(.*\)",/\1/p' + ) + + if [ -z "$gists" ] + then + echo "No gists found on this page. Trying again." + retries=$(( retries + 1 )) + continue + fi + + for gist in $gists + do + backup $gist + done + + page=$(( page + 1 )) + retries=0 done - - page=$(( page + 1 )) - retries=0 done echo "No gists found (anymore). Not trying again." From cad97d46943e3b146ef3b3e9510bc099bf84344a Mon Sep 17 00:00:00 2001 From: Felix Bartels Date: Wed, 13 May 2015 07:07:13 +0200 Subject: [PATCH 3/4] revert back to original script --- gist-backup | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/gist-backup b/gist-backup index 27c7f73..9ed21d3 100755 --- a/gist-backup +++ b/gist-backup @@ -92,35 +92,32 @@ backup() { fi } -for url in https://api.github.com/gists https://api.github.com/gists/starred +page=1 +retries=0 +MAX_RETRIES=5 +while [ $retries -lt $MAX_RETRIES ] do - page=1 - retries=0 - MAX_RETRIES=5 - while [ $retries -lt $MAX_RETRIES ] + echo "Requesting Gist page: $page" + + gists=$( + curl -s -H "Authorization: token $token" -d "page=$page" -G https://api.github.com/gists | + sed -n 's/.*git_pull_url": "\(.*\)",/\1/p' + ) + + if [ -z "$gists" ] + then + echo "No gists found on this page. Trying again." + retries=$(( retries + 1 )) + continue + fi + + for gist in $gists do - echo "Requesting Gist page: $page from $url" - - gists=$( - curl -s -H "Authorization: token $token" -d "page=$page" -G $url | - sed -n 's/.*git_pull_url": "\(.*\)",/\1/p' - ) - - if [ -z "$gists" ] - then - echo "No gists found on this page. Trying again." - retries=$(( retries + 1 )) - continue - fi - - for gist in $gists - do - backup $gist - done - - page=$(( page + 1 )) - retries=0 + backup $gist done + + page=$(( page + 1 )) + retries=0 done echo "No gists found (anymore). Not trying again." From 10fdaeb7c36b5329fce40196d6d8e7ceb5cc1e06 Mon Sep 17 00:00:00 2001 From: Felix Bartels Date: Wed, 13 May 2015 07:31:07 +0200 Subject: [PATCH 4/4] reimplement backup of starred gists according to the suggestion of aprescott --- gist-backup | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gist-backup b/gist-backup index 9ed21d3..5186065 100755 --- a/gist-backup +++ b/gist-backup @@ -9,8 +9,18 @@ # # gist-backup ~/gist-backups # +# In addition to your own gists you can also backup your starred gists +# or (public) gists of a defined user by putting the gists url in an +# environment variable. +# +# Example: +# +# GIST_URL=https://api.github.com/gists/starred gist-backup ~/gist-backups/starred +# GIST_URL=https://api.github.com/users/aprescott/gists gist-backup ~/gist-backups/aprescott +# token=$(git config --get github.gist.oauth.token) +url=${GIST_URL:-https://api.github.com/gists} usage() { cat <