Created
November 30, 2017 21:31
-
-
Save melizeche/4d5ffe55e65b8653638f1329a7dfba78 to your computer and use it in GitHub Desktop.
Backup/clone several git repositories with all the branches, cronjob prepared
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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