{"id":187,"date":"2019-08-07T21:01:44","date_gmt":"2019-08-07T21:01:44","guid":{"rendered":"https:\/\/tobyslab.com\/?p=187"},"modified":"2019-08-07T21:01:44","modified_gmt":"2019-08-07T21:01:44","slug":"backing-up-github","status":"publish","type":"post","link":"https:\/\/tobyslab.com\/?p=187","title":{"rendered":"Backing up GitHub"},"content":{"rendered":"\n<p>I host all my code in GitHub now that it is free for private as well as public repositories. Before that I used GitLab, which I may return if I implement CI\/CD on my own personal projects.<\/p>\n\n\n\n<p>One of the concerns I have is what happens if GitHub is unavailable? I would like a complete daily copy of my GitHub repositories available on-demand.<\/p>\n\n\n\n<p>Luckily there is a great python package available that <a href=\"https:\/\/github.com\/josegonzalez\/python-github-backup\">does just this.<\/a> Once installed, adding a shell variable GIT_TOKEN, using a simple bash script and crontab you can have full daily Git backups. Just replace username in the script. If you&#8217;re in an organization you&#8217;ll have to add &#8211;organization, also.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n_GIT_USER=\"username\"\n_NOW=$(date +\"%Y-%m-%d\")\n\ngithub-backup $_GIT_USER --token $GIT_TOKEN --output-directory \/tmp\/gitbackup --repositories --private\ncd \/tmp\ntar -jcf github-backup-$_NOW.tbz2 tobyslab\/\nmv github-backup-$_NOW.tbz2 ~\/github-backups<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I host all my code in GitHub now that it is free for private as well as public repositories. Before that I used GitLab, which I may return if I implement CI\/CD on my own personal projects. One of the concerns I have is what happens if GitHub is unavailable? I would like a complete daily copy of my GitHub repositories available on-demand. Luckily there is a great python package available that does just this. Once installed, adding a shell variable GIT_TOKEN, using a simple bash script and crontab you can have full daily Git backups. Just replace username in the script. If you&#8217;re in an organization you&#8217;ll have to add &#8211;organization, also.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[10,8],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/posts\/187"}],"collection":[{"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tobyslab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=187"}],"version-history":[{"count":1,"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/posts\/187\/revisions"}],"predecessor-version":[{"id":188,"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/posts\/187\/revisions\/188"}],"wp:attachment":[{"href":"https:\/\/tobyslab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tobyslab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tobyslab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}