Tuesday, July 28, 2009

Backup git and svn Projects to tar.gz

The following are some ways to backup git and svn projects to tar.gz.

If backing up master of git repo, this will put a nameofproject.tar.gz in the previous dir:

cd (your git project dir)
git archive master | gzip > ../nameofproject.tar.gz

If backing up the svn dir you're in, this will put a nameofproject.tar.gz in the previous dir:

cd (your svn project dir)
rm -rf /tmp/svnexport/;svn export . /tmp/svnexport;tar -C /tmp/svnexport/ -czvf ../nameofproject.tar.gz .

For a subversion equivalent of git-archive for creating a bit identical version of the tar.gz each time, use the following from Sven Eckelmann:
* http://www.narfation.org/2009/01/08/creating-recreatable-tar-gz-from-svn

(Here is the copied/pasted bash script from that Sven's post...)

#! /bin/sh
set -e
if [ "$1" = "" ] || [ "$2" = "" ]; then
        echo "Usage: $0 REPO TARGET"
        exit 1
fi
umask 000
REPO="$1"
RELEASENAME="$2"
MANIFEST="`mktemp -t`"
trap "rm -rf \"${RELEASENAME}\"; rm -f \"${MANIFEST}\"" 0
rm -rf "${RELEASENAME}"*
svn export "${REPO}" "${RELEASENAME}"
find "${RELEASENAME}" -type f |sed 's/^\.*\/*//'|sort > "$MANIFEST"
tar cf "${RELEASENAME}".tar --owner 0 --group 0 --numeric-owner --no-recursion --files-from "$MANIFEST"
gzip -n -m -f "${RELEASENAME}".tar
md5sum -b "${RELEASENAME}".tar.gz > "${RELEASENAME}".tar.gz.md5
sha1sum -b "${RELEASENAME}".tar.gz > "${RELEASENAME}".tar.gz.sha1
gpg -a --detach-sign "${RELEASENAME}".tar.gz

No comments: