<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by David Alvarez Debrot on Medium]]></title>
        <description><![CDATA[Stories by David Alvarez Debrot on Medium]]></description>
        <link>https://medium.com/@david.alvarez_58948?source=rss-23f555b523a5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UyPDqVFYIWTgLqICL2O3eA.jpeg</url>
            <title>Stories by David Alvarez Debrot on Medium</title>
            <link>https://medium.com/@david.alvarez_58948?source=rss-23f555b523a5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 01:50:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@david.alvarez_58948/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using GitHub to backup files]]></title>
            <link>https://medium.com/@david.alvarez_58948/using-github-to-backup-files-ffd0d624d69?source=rss-23f555b523a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffd0d624d69</guid>
            <category><![CDATA[backup]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[David Alvarez Debrot]]></dc:creator>
            <pubDate>Fri, 07 Oct 2022 15:00:54 GMT</pubDate>
            <atom:updated>2022-10-07T15:04:49.000Z</atom:updated>
            <content:encoded><![CDATA[<p>The backup logic presented in this story will work for any file system. Here, we’ll be backing up icCube files.</p><p>A bit of background, <a href="https://www.iccube.com/">icCube</a> is a software for embedding analytics. As part of our development setup we have an icCube instance running with a set of reports that we use for testing and development purpose. The dev team works daily on those reports, so files are created, modified and deleted as for any code files. As we use GitHub for development, a backup solution using GitHub was a natural fit.</p><h4>1. Create a GitHub repository</h4><p>The first step is to create a private GitHub repository with a README.md file. Later on, we are going to use this README.md file to tag the backups.</p><p>The repository will be something like : <em>myCompany/myBackupRepo</em></p><p>Nothing more is needed for now in Github.</p><h4>2. Setup Git in our server</h4><p>If not already installed, you have to install Git in your server (<em>Debian Linux</em>):</p><pre>sudo apt update<br>sudo apt install git<br># check git installed<br>git --version</pre><p>For security, we use a <em>deploy key</em> as authentication method to access GitHub. You need to create a public/private key in your server (same email as the one used in your GitHub repo) :</p><pre>ssh-keygen -t ed25519 -C &quot;myEmail@myCompany.com&quot;</pre><p>This should have created both keys in a local directory (usually ~/.ssh).</p><p>Now use the public key (<em>ed25519.pub)</em> to create a <em>deploy key</em> to access the repository from your server. The key needs <strong>write access</strong> to the Repo :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YhN7073AI8iKX7S8nXJhkA.png" /></figure><p>Eventually, add in the server’s SSH configuration file (<em>usually ~/.ssh/config</em>) an alias entry for your repository :</p><pre>Host github-dev-backup<br>        HostName github.com<br>        IdentityFile=~/.ssh/id_ed25519</pre><p>And that’s it. You can clone your repository in your server. We use <em>git-backup</em> directory :</p><pre>mv ~/git-backup/<br>git clone git@github-dev-backup:<em>myCompany/myBackupRepo</em></pre><p>And with this you finish creating a repository and using a <em>deploy key </em>to access GitHub from your server. More documentation on <em>deploy key</em> and Github can be found <a href="https://docs.github.com/en/developers/overview/managing-deploy-keys">here</a>.</p><h4>3. Synchronise Git with our local files</h4><p>We want to synchronise the application files (in our case the reports) with the local git repository and push all changes to the Git server.</p><p>You have to create a script that will look like (<em>runIC3backup.sh</em>) :</p><pre>#!/bin/sh<br><br>IC3_SOURCE=/home/dev/icCube/9494/ic3data/docsRepository<br>GIT_HOME=/home/userName/git-backup<br>GIT_TARGET=$GIT_HOME/reports</pre><pre>#<br># Force pull (needed if you have other files in the repository, i.e. actions)<br>#<br>cd $GIT_HOME<br>git fetch --all; git reset --hard HEAD; git merge @{u}#</pre><pre>#<br># sync icCube files<br># <br>rsync -r $IC3_SOURCE $GIT_TARGET<br><br>#<br># if &#39;force&#39; is the first argument, <br>#   change first line README.md to add current date (this will force a push on each call)<br># <br>if [ &quot;force&quot; = $1 ]; then<br>    currentDate=`date &#39;+%d.%m.%Y %k:%M:%S&#39;`<br>    tag=&quot;###  $currentDate&quot;<br>    sed -i &quot;1s/.*/$tag/&quot; $GIT_HOME/README.md<br>fi <br><br>#<br># Force add/commit/push <br>#<br>git add -A .<br>git commit -m &quot;backup&quot; <br>git push -f</pre><p>The script has a <em>force </em>argument that will change the first line of the README.md file to the server’s current date. This will <em>force</em> a commit even though no other file might have changed (this will be used at the end)</p><p>To be safe <strong>check your rsync before running the script !</strong></p><pre>rsync -r -n $IC3_SOURCE $GIT_TARGET</pre><p>After testing the script is fine, we can add the script to our crontab tasks. In this example we backup each hour without a force, and perform a daily backup with a force.</p><p>Edit your crontab :</p><pre>crontab -e</pre><p>Add the following lines :</p><pre>0 22 * * * /home/userName/git-backup/backup-reports.sh force<br>30 * * * * /home/userName/git-backup/backup-reports.sh</pre><h4>GitHub action to check backup (optional)</h4><p>The final task is to add an action to your repository to check that the scripts are running on the server.</p><p>For this, we are going to check the time difference between the latest Git commit and the action start. If this difference is greater than 8 hours it will fail. Remember, you are notified by email when a GitHub action fails, i.e. if the backup script is not working.</p><p>This is the rationale of the ‘force’ in the shell, ensuring there is at least a file change when running the script.</p><pre>name: CheckBackup<br><br>on:<br>  workflow_dispatch:<br>  schedule:<br>    - cron: &#39;0 1 * * *&#39;  # every day at 1:00am<br>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br><br>    steps:<br>    - uses: actions/checkout@v3<br><br>    - name: Check dates difference<br>      run: |<br>        echo &quot;GitHub last update : &quot; +  `git log -1 --format=%cd$`<br>        echo &quot;Now : &quot; +  `date`<br>        let now=`date +%s`<br>        let backupTime=`git log -1 --format=%cd$ --date=raw | grep -o &quot;^\w*\b&quot;`<br>        deltaHours=$((now-backupTime))<br>        deltaHours=$((deltaHours/3600))<br>        echo &#39;Delta of : &#39; + $deltaHours<br>        if [ $deltaHours -ge 8 ]; then<br>             echo &#39;failed : &#39; + $deltaHours + &#39;hours&#39;<br>             exit 1<br>        else     <br>             echo &#39;ok&#39;<br>             exit 0<br>        fi</pre><p>Note that the date of the README.md file is the one from your server not the one of GitHub.</p><p>And this is it, you got your files backed up in GitHub.</p><p>Hope it helps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffd0d624d69" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>