Skip to content

Instantly share code, notes, and snippets.

@melizeche
Created November 30, 2017 21:31
Show Gist options
  • Save melizeche/4d5ffe55e65b8653638f1329a7dfba78 to your computer and use it in GitHub Desktop.
Save melizeche/4d5ffe55e65b8653638f1329a7dfba78 to your computer and use it in GitHub Desktop.
Backup/clone several git repositories with all the branches, cronjob prepared
#!/bin/bash
BACKUP_DIR=~/backups/git_backups/
REPOS="[email protected]:melizeche/listaHu.git [email protected]:melizeche/dolarPy.git"
for repo in $REPOS;do
repo_dir=$(echo $repo | sed 's/.*\///')
repo_name=$(echo $repo_dir | sed 's/\.[^.]*$//')
FINAL_BACKUP_DIR=$BACKUP_DIR"`date +\%Y-\%m-\%d`/"
FINAL_REPO_DIR=$FINAL_BACKUP_DIR$repo_name
echo "Backing up "$repo_name in $FINAL_REPO_DIR
#Create directory with the date
if ! mkdir -p $FINAL_BACKUP_DIR; then
echo "Cannot create backup directory in $FINAL_BACKUP_DIR. Go and fix it!" 1>&2
exit 1;
fi;
git clone --mirror $repo $FINAL_REPO_DIR/.git
cd $FINAL_REPO_DIR
git config --unset core.bare
git checkout master
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment