Skip to content

Instantly share code, notes, and snippets.

@mschuwalow
Last active June 30, 2016 17:22
Show Gist options
  • Select an option

  • Save mschuwalow/8c5d24d82233c146c53131e36e394196 to your computer and use it in GitHub Desktop.

Select an option

Save mschuwalow/8c5d24d82233c146c53131e36e394196 to your computer and use it in GitHub Desktop.

Revisions

  1. mschuwalow revised this gist Jun 30, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion backup-gitlab.fish
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    set BACKUP_DIR /home/pi/backup/gitlab
    set TOKEN xR2_71SwD-xnj4mkoyeL
    set TOKEN
    set PRUNE_AFTER 3

    set TSTAMP (date "+%Y%m%d-%H%M")
  2. mschuwalow revised this gist Jun 30, 2016. 1 changed file with 14 additions and 8 deletions.
    22 changes: 14 additions & 8 deletions backup-gitlab.fish
    Original file line number Diff line number Diff line change
    @@ -1,30 +1,36 @@
    set BACKUP_DIR
    set TOKEN
    set BACKUP_DIR /home/pi/backup/gitlab
    set TOKEN xR2_71SwD-xnj4mkoyeL
    set PRUNE_AFTER 3

    set TSTAMP (date "+%Y%m%d-%H%M")

    set API https://gitlab.com/api/v3/projects/

    function tgz
    echo $argv
    tar -zcf {$argv}.tar.gz $argv
    rm -rf $argv
    end

    echo "=== INITIALIZING ==="

    echo "Using backup directory $BACKUP_DIR"
    mkdir -p $BACKUP_DIR

    set REPOLIST (curl -H "PRIVATE-TOKEN: $TOKEN" https://gitlab.com/api/v3/projects/ | awk -v "ORS=," '{print}'| sed 's/,/\n/g' | grep "http_url_to_repo" | sed "s/\"http_url_to_repo\"://" | sed "s/https/http/")
    set REPOLIST (curl -H "PRIVATE-TOKEN: $TOKEN" https://gitlab.com/api/v3/projects/ | awk -v "ORS=," '{print}'| sed 's/,/\n/g' | grep "http_url_to_repo" | sed "s/\"http_url_to_repo\"://" | sed "s/https/http/" | sed 's/"//' | sed 's/"//')

    for REPO in $REPOLIST
    echo "Backing up $REPO"
    set TEMP (echo $REPO | sed "s/https:.*\///" | sed "s/.git//")
    git clone --quiet --mirror $REPO {$BACKUP_DIR}/{$TEMP}-{$TSTAMP}
    tgz {$GHBU_BACKUP_DIR}/{$TEMP}-{$TSTAMP}
    set TEMP (echo $REPO | sed "s/http:.*\///" | sed "s/.git//")
    git clone $REPO {$BACKUP_DIR}/{$TEMP}-{$TSTAMP}
    tgz {$BACKUP_DIR}/{$TEMP}-{$TSTAMP}
    end

    echo "=== PRUNING ==="
    echo "Pruning backup files $PRUNE_AFTER days old or older."
    echo "Found `find $BACKUP_DIR -name '*.tar.gz' -mtime +$PRUNE_AFTER | wc -l` files to prune."
    echo Found (find $BACKUP_DIR -name '*.tar.gz' -mtime +{$PRUNE_AFTER} | wc -l) files to prune.

    find $BACKUP_DIR -name -mtime +$PRUNE_AFTER -exec rm -fv {} > /dev/null
    rm -rf (find $BACKUP_DIR -name '*.tar.gz' -mtime +{$PRUNE_AFTER})


    echo "=== DONE ==="
  3. mschuwalow revised this gist Jun 30, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion backup-gitlab.fish
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ echo "=== INITIALIZING ==="
    echo "Using backup directory $BACKUP_DIR"
    mkdir -p $BACKUP_DIR

    set REPOLIST (curl -H "PRIVATE-TOKEN: $TOKEN" $API | awk -v "ORS=," '{print}'| sed 's/,/\n/g' | grep "http_url_to_repo" | sed "s/\"http_url_to_repo\"://" | sed "s/\"//" | sed "s/\"//")
    set REPOLIST (curl -H "PRIVATE-TOKEN: $TOKEN" https://gitlab.com/api/v3/projects/ | awk -v "ORS=," '{print}'| sed 's/,/\n/g' | grep "http_url_to_repo" | sed "s/\"http_url_to_repo\"://" | sed "s/https/http/")

    for REPO in $REPOLIST
    echo "Backing up $REPO"
  4. mschuwalow revised this gist Jun 22, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion backup-gitlab.fish
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    set BACKUP_DIR /home/maxim/temp/testssd
    set BACKUP_DIR
    set TOKEN
    set PRUNE_AFTER 3

  5. mschuwalow created this gist Jun 22, 2016.
    31 changes: 31 additions & 0 deletions backup-gitlab.fish
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    set BACKUP_DIR /home/maxim/temp/testssd
    set TOKEN
    set PRUNE_AFTER 3

    set TSTAMP (date "+%Y%m%d-%H%M")

    set API https://gitlab.com/api/v3/projects/

    echo "=== INITIALIZING ==="

    echo "Using backup directory $BACKUP_DIR"
    mkdir -p $BACKUP_DIR

    set REPOLIST (curl -H "PRIVATE-TOKEN: $TOKEN" $API | awk -v "ORS=," '{print}'| sed 's/,/\n/g' | grep "http_url_to_repo" | sed "s/\"http_url_to_repo\"://" | sed "s/\"//" | sed "s/\"//")

    for REPO in $REPOLIST
    echo "Backing up $REPO"
    set TEMP (echo $REPO | sed "s/https:.*\///" | sed "s/.git//")
    git clone --quiet --mirror $REPO {$BACKUP_DIR}/{$TEMP}-{$TSTAMP}
    tgz {$GHBU_BACKUP_DIR}/{$TEMP}-{$TSTAMP}
    end

    echo "=== PRUNING ==="
    echo "Pruning backup files $PRUNE_AFTER days old or older."
    echo "Found `find $BACKUP_DIR -name '*.tar.gz' -mtime +$PRUNE_AFTER | wc -l` files to prune."

    find $BACKUP_DIR -name -mtime +$PRUNE_AFTER -exec rm -fv {} > /dev/null


    echo "=== DONE ==="
    echo "GitHub backup completed."