Open main menu

Changes

Git svn

3,329 bytes added, 23:37, 23 July 2013
ls -la ~/.netrc
cat ~/.netrc
 
== Setup cronjob ==
Checking each 15 minutes
<source lang="bash">
crontab -e
 
# Add
*/15 * * * * $HOME/backup/nmrrelax_sync_svn_git.sh
</source>
 
== Sync script from SVN to Hithub ==
<source lang="bash">
#!/bin/bash
# -*- coding: UTF-8 -*-
# Script for syncing SVN to git automatically using cron.
#
 
# exec test
exec_test () {
[ $? -eq 0 ] && echo "-- Command successfully executed" || echo "-- Command failed; exit 1"
}
 
# Filenames
urlhost="http://www.mail-archive.com/relax-commits@gna.org/"
mydate=`date '+%Y%m%d_%H%M'`
mytime=`date '+%T %Y%m%d'`
 
# Set paths to do the mail sync
backupfolder="${HOME}/backup/nmrrelax_svn_git_sync"
backupfolderurl="${backupfolder}/commit_url_dumps"
dumpdate="commits_url.txt"
curfile="currev.txt"
prevfile="prevrev.txt"
branchfile="curbranch.txt"
mkdir -p $backupfolder $backupfolderurl
 
# Set paths to GIT
relax=$HOME/backup/relax
relax_trunk=${relax}/relax_trunk
relax_disp=${relax}/relax_disp
 
# Logging
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>>${backupfolder}/nmrrelax_svn_git_sync.log 2>&1
# Everything below will go to the log file
 
dump_base () {
echo "###########################"
echo "STARTING on: $mytime"
echo "Dumping URL webpage revisions..."
#lftp -e "open ftp://${dbuser}:${dbpwd}@${dbhost} && mirror --no-perms --exclude-glob backup_scripts/ --exclude-glob cache/ --exclude-glob LocalSettings.php --parallel=10 && bye"
lynx -dump $urlhost > ${backupfolderurl}/${dumpdate}
currev=`grep -E '^ \* \[5\]r' ${backupfolderurl}/${dumpdate} | awk '{print $2}' | cut -c5-`
branch=`grep -E '^ \* \[5\]r' -A 5 ${backupfolderurl}/${dumpdate} | grep -m 1 -e '\/branches\/relax_disp\|\/trunk'`
 
# Echo revision to log
echo "Current revision is: $currev"
# Write to current revision file
echo "$currev" > ${backupfolder}/${curfile}
 
# Write to current branch file
echo "$branch" > ${backupfolder}/${branchfile}
 
# Make string replacements in branch file
## Replace empty spaces with nothing
sed -i 's/ \+//g' ${backupfolder}/${branchfile}
## Replace with relax trunk
sed -i "s/.*\/trunk.*/trunk/g" ${backupfolder}/${branchfile}
## Replace with relax disp
sed -i "s/.*\/branches\/relax_disp.*/relax_disp/g" ${backupfolder}/${branchfile}
# Set current branch from the file
curbranch=`cat ${backupfolder}/${branchfile}`
 
# Echo branch to log
echo "This is branch: $curbranch"
 
 
# If previous revision does not exist, then create it.
if [ ! -e ${backupfolder}/${prevfile} ] ; then
touch ${backupfolder}/${prevfile}
fi
}
 
do_git_sync () {
echo "Checking if need for for new commits ..."
DIFF=`diff -q ${backupfolder}/${curfile} ${backupfolder}/${prevfile}`
echo -e "Difference between current revision and current current revision is:\n${DIFF}\n"
DIFFARR=($DIFF)
LENDIFFARR=${#DIFFARR[@]}
if [ "$LENDIFFARR" -gt "0" ]
then
 
echo -e "#Now doing git sync for: $curbranch"
echo "Changed revision to ${currev}"
echo "$currev" > ${backupfolder}/${prevfile}
 
if [ "$curbranch" == "trunk" ]
then
echo "Now doing something for trunk"
cd $relax_trunk
git svn fetch
git rebase --onto remotes/git-svn
git push origin master
fi
 
if [ "$curbranch" == "relax_disp" ]
then
echo "Now doing something for relax_disp"
cd $relax_disp
git svn fetch
git rebase --onto remotes/git-svn
git push origin master
fi
 
fi
}
 
dump_base ; exec_test
do_git_sync ; exec_test
 
echo "Done, quit!"
</source>
= See also =
[[Category:git]]