Hello,
We most of us use GIT as version control for our projects. Many of us use github or our own servers for managing git repositories.
If you are using github, then github will take care of backing up your repositories. But if you are having your own server for storing your repositories, then you need to ensure that the repositories are being backed up regularly (may be once or twice in a day).
There are various options through which you can backup your git by using git bundle or other rails scripts. As i am looking at different options i found out (actually my friend Prashant found this) git clone using mirror option. This basically mirrors your git repository including all branches.
Below is a simple script which will basically backup all the git repositories present in a specific location into FTP drive.
#!/bin/bash
# GIT Backup Script
# Copyright (c) 2012-2013 Asif Noor (asif@azrisolutions.com)
# This script is licensed under GNU GPL version 2.0 or above.
current_date=`date +%d-%m-%Y-%H-%M-%S`
echo GIT Backup Started $current_date >> /var/log/git-backup.log
### Enable backups ###
BAKGIT="1"
GIT_CODEBASE_DIR="GIT_DIR" //example: "/opt/git/"
GIT_CREDENTIALS="username:passwd"
backup_dir="/backup/git/"
cd $GIT_CODEBASE_DIR
for file in *.git; do
file_backup=$file"_backup.git"
//The below command will mirror the entire git including branches.
git clone --mirror $GIT_CODEBASE_DIR$file $file_backup
tar cf $file_backup.tar $file_backup
bzip2 $file_backup.tar
mv $file_backup.tar.bz2 $backup_dir
echo $file_backup
rm -rf $file_backup
done
BAKFILES="0"
BAKENCRYPT="0"
BAKFTP="1"
BAKDELETE="1"
### FTP server Setup ###
FTPD="//incremental"
FTPU="FTPUSER"
FTPP="FTPPASS"
FTPS="FTPHOST"
NCFTP="$(which ncftpput)"
### SYSTEM STEUP ###
HOST="$(hostname)"
NOW=$(date +"%Y%m%d-%H%M%S")
EMAILID="mail@email.com"
### Dump backup using FTP ###
#Start FTP backup using ncftp
if [ "$BAKFTP" -eq "1" ]
then
ncftp -u"$FTPU" -p"$FTPP" $FTPS<
mkdir $HOST
mkdir $HOST/$NOW
cd $HOST/$NOW
lcd $backup_dir
mput *
quit
EOF
fi
current_date=`date +%d-%m-%Y-%H-%M-%S`
echo Backup Ended $current_date >> /var/log/git-backup.log
We most of us use GIT as version control for our projects. Many of us use github or our own servers for managing git repositories.
If you are using github, then github will take care of backing up your repositories. But if you are having your own server for storing your repositories, then you need to ensure that the repositories are being backed up regularly (may be once or twice in a day).
There are various options through which you can backup your git by using git bundle or other rails scripts. As i am looking at different options i found out (actually my friend Prashant found this) git clone using mirror option. This basically mirrors your git repository including all branches.
Below is a simple script which will basically backup all the git repositories present in a specific location into FTP drive.
#!/bin/bash
# GIT Backup Script
# Copyright (c) 2012-2013 Asif Noor (asif@azrisolutions.com)
# This script is licensed under GNU GPL version 2.0 or above.
current_date=`date +%d-%m-%Y-%H-%M-%S`
echo GIT Backup Started $current_date >> /var/log/git-backup.log
### Enable backups ###
BAKGIT="1"
GIT_CODEBASE_DIR="GIT_DIR" //example: "/opt/git/"
GIT_CREDENTIALS="username:passwd"
backup_dir="/backup/git/"
cd $GIT_CODEBASE_DIR
for file in *.git; do
file_backup=$file"_backup.git"
//The below command will mirror the entire git including branches.
git clone --mirror $GIT_CODEBASE_DIR$file $file_backup
tar cf $file_backup.tar $file_backup
bzip2 $file_backup.tar
mv $file_backup.tar.bz2 $backup_dir
echo $file_backup
rm -rf $file_backup
done
BAKFILES="0"
BAKENCRYPT="0"
BAKFTP="1"
BAKDELETE="1"
### FTP server Setup ###
FTPD="//incremental"
FTPU="FTPUSER"
FTPP="FTPPASS"
FTPS="FTPHOST"
NCFTP="$(which ncftpput)"
### SYSTEM STEUP ###
HOST="$(hostname)"
NOW=$(date +"%Y%m%d-%H%M%S")
EMAILID="mail@email.com"
### Dump backup using FTP ###
#Start FTP backup using ncftp
if [ "$BAKFTP" -eq "1" ]
then
ncftp -u"$FTPU" -p"$FTPP" $FTPS<
mkdir $HOST
mkdir $HOST/$NOW
cd $HOST/$NOW
lcd $backup_dir
mput *
quit
EOF
fi
current_date=`date +%d-%m-%Y-%H-%M-%S`
echo Backup Ended $current_date >> /var/log/git-backup.log
NOTE: In the script, you need to put the actual logins to get it working. If you do not have ftp drive, you can copy to other server as well. Do let me know your comments about the script.