Skip to content

Instantly share code, notes, and snippets.

@ricardodantas
Created October 2, 2017 16:36
Show Gist options
  • Select an option

  • Save ricardodantas/c4e41d928939e69ab9c22fadfa973712 to your computer and use it in GitHub Desktop.

Select an option

Save ricardodantas/c4e41d928939e69ab9c22fadfa973712 to your computer and use it in GitHub Desktop.
Update all folders which are a valid git repository and create a tar ball (package.tar)
#!/bin/bash
BACKUP_FOLDER=tmp-bkp
echo "=> Creating temp backup folder..."
mkdir -p $BACKUP_FOLDER
for f in *; do
if [[ -d $f ]]; then
echo "=> Updating $f..."
cd $f
if [ -d .git ]; then
git clean -df
git checkout -- .
git checkout master
git pull
echo "=> Creating a package for $f..."
git archive --format zip --output "../$BACKUP_FOLDER/$f.zip" master -0
fi
cd ../
fi
done
echo "=> Creating final package..."
tar -cvf package.tar $BACKUP_FOLDER
rm -fr $BACKUP_FOLDER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment