Skip to content

Instantly share code, notes, and snippets.

@alikalantaripor
Last active April 21, 2021 14:35
Show Gist options
  • Save alikalantaripor/bc1425ab4388302de79f31b535b3d3b9 to your computer and use it in GitHub Desktop.
Save alikalantaripor/bc1425ab4388302de79f31b535b3d3b9 to your computer and use it in GitHub Desktop.
Backup git repositories
backup_repositories(){
gh repo list ownerusername > 'temp.txt'
cut -f1 'temp.txt' > 'repositories.txt'
while IFS= read -r repository; do
echo "## Start Backup from $repository"
directory_name=$(cut -d "/" -f2 <<< $repository)
if cd $directory_name;
then cd '..';
else gh repo clone $repository;
fi
cd $directory_name
git checkout master
git pull
git checkout develop
git pull
git checkout main
git pull
cd ..
echo "## Backup from $repository Finished"
done < repositories.txt
mkdir $(date +'%Y.%m.%d')
while IFS= read -r folder; do
echo "## Start Compress & move $folder ##"
directory_name=$(cut -d "/" -f2 <<< $folder)
zip -r -9 $directory_name $directory_name
mv $directory_name.zip $(date +'%Y.%m.%d')
echo "## End Compress & move $folder ##"
done < repositories.txt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment