Last active
March 2, 2018 04:45
-
-
Save icoloma/2af0aaa087d918f15fe9 to your computer and use it in GitHub Desktop.
Backup a Github repository into a local file. Useful when retiring a Github repository, but keeping a backup copy for a rainy day in Dropbox / Drive / Box.
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 the repositories indicated in the command line | |
# Example: | |
# bin/backup user1/repo1 user1/repo2 | |
set -e | |
for i in $@; do | |
FILENAME=$(echo $i | sed 's/\//-/g') | |
echo "== Backing up $i to $FILENAME.bak" | |
git clone [email protected]:$i $FILENAME.git --mirror | |
cd "$FILENAME.git" | |
git bundle create ../$FILENAME.bak --all | |
cd .. | |
rm -rf $i.git | |
echo "== Repository saved as $FILENAME.bak" | |
done |
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 | |
# Restore the repository indicated in the command line | |
# Example: | |
# bin/restore filename.bak | |
set -e | |
FOLDER_NAME=$(echo $1 | sed 's/.bak//') | |
git clone --bare $1 $FOLDER_NAME.git |
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 | |
# Verify the backup file. Both the .bak file and the corresponding .git folder must exist | |
# Example: | |
# bin/verify filename1.bak filename2.bak | |
set -e | |
for i in $@; do | |
FOLDER_NAME=$(echo $i | sed 's/.bak/.git/') | |
echo "== Contents of $i" | |
cd $FOLDER_NAME | |
echo "Last commit: $(git log --name-status HEAD^..HEAD -n1 | egrep '( )|(Date)' )" | |
cd .. | |
echo | |
git bundle list-heads $i | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment