Kiln »
KilnSupportScriptsPowershell Scripts to help monitor a Kiln environment. Contact Fog Creek support before using.
Alias information
is an alias for .
Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
################################## This script will migrate repositories from one Kiln Server to another. It should work as long as# there are no name clashes between the old server and the new one, but it has only be tested with a # completely empty new server. #
# The script should be run on a machine which has sufficient disk space to clone copies of ALL of the
# repositories from the old kiln server. This means it also requires that Mercurial be installed in order to run.
-+#+# Beware: Branches will not migrate properly if the parent repo has been changed since the original point of the branch!importsysimportosimporturllibimporturllib2importurlparsefromQueueimportQueuetry:importjsonexceptImportError:importsimplejsonasjson# Set debug to 0 for errors only, 1 for basic output, 2 for verbose outputdebug=1sourceServer='https://my.kilnhg.com'sourceToken='SECRET'destinationServer='http://server/fogbugz/kiln'destinationToken='SECRET'defdebug_print(message,level=1):if(debug>=level):printmessage# We cycle through the heirarchy of objects and push them over to the new server.# Projects contain Groups, which in turn contain Repositories, so we have a nested loop in that order.# Note that this does NOT transfer the Users from the previous server nor any specific # permissions on the Projects/Groups/Repositories.# Create a dictionary from old ixRepos to new ones. # oldIxRepo = 123# newIxRepo = 456# repo_map[123] = 456repo_map={}# A list of pairs indicating the parent associations we will have to recreate. (old_ixrepo, old_parent_ixrepo)old_parent_associations=[]# Load all the source projectssrc_projects=json.load(urllib2.urlopen('%s/Api/1.0/project/?token=%s'%(sourceServer,sourceToken)))###### PROJECT LEVEL LOOP ######forsrc_projectinsrc_projects:debug_print("Working on project '%s'"%(src_project['sName']))debug_print("SOURCE PROJECT DATA:\n"+str(src_project),2)dest_project=None# Try to find the project on the Destination Serverdest_projects=json.load(urllib2.urlopen('%s/Api/1.0/Project?token=%s'%(destinationServer,destinationToken)))fora_dest_projectindest_projects:if(a_dest_project['sName']==src_project['sName']):dest_project=json.load(urllib2.urlopen('%s/Api/1.0/Project/%s?token=%s'%(destinationServer,a_dest_project['ixProject'],destinationToken)))debug_print(" - Found an existing match on the destination server. ixProject = %s"%(dest_project['ixProject']))debug_print(" - DESTINATION PROJECT DATA:\n"+str(dest_project),2)# If we don't find an existing project, then create a new project with the information we grabbed from the old serverif(notdest_project):data=urllib.urlencode({'token':destinationToken,'sName':src_project['sName'], \
'sDescription':src_project['sDescription'],'permissionDefault':src_project['permissionDefault']})dest_project=json.load(urllib2.urlopen('%s/Api/1.0/Project/Create'%(destinationServer),data))debug_print(" + Created a new Project on the destination server. ixProject = %s"%(dest_project['ixProject']))debug_print(" + DESTINATION PROJECT DATA:\n"+str(dest_project),2)###### REPOSITORY GROUP LEVEL LOOP ######forsrc_repo_groupinsrc_project['repoGroups']:debug_print(" Working on Group '%s'"%(src_repo_group['sName']))debug_print(" SOURCE REPO GROUP DATA:\n"+str(src_repo_group),2)dest_repo_group=None# Try to find the project on the Destination Serverdest_repo_groups=dest_project['repoGroups']fora_dest_repo_groupindest_repo_groups:if(a_dest_repo_group['sName']==src_repo_group['sName']):dest_repo_group=json.load(urllib2.urlopen('%s/Api/1.0/RepoGroup/%s?token=%s'%(destinationServer,a_dest_repo_group['ixRepoGroup'],destinationToken)))debug_print(" - Found an existing match on the destination server. ixRepogroup = %s"%(dest_repo_group['ixRepoGroup']))debug_print(" - DESTINATION REPO GROUP DATA:\n"+str(dest_repo_group),2)# If we don't find an existing project, then create a new project with the information we grabbed from the old serverif(notdest_repo_group):data=urllib.urlencode({'token':destinationToken,'sName':src_repo_group['sName'],'ixProject':dest_project['ixProject']})dest_repo_group=json.load(urllib2.urlopen('%s/Api/1.0/RepoGroup/Create/'%(destinationServer),data))debug_print(" + Created a new Repository Group on the destination server. ixRepoGroup = %s"%(dest_repo_group['ixRepoGroup']))debug_print(" + DESTINATION REPO GROUP DATA:\n"+str(dest_repo_group),2)# We build a queue of the repositories so that we can easily wait to process any repos that need parents created firstq=Queue()forsrc_repoinsrc_repo_group['repos']:q.put(src_repo)###### REPOSITORY LEVEL LOOP ######while(notq.empty()):src_repo=q.get()# If the repo has a parent that has NOT been created in the destination yet, then re-enqueue it for laterif((src_repo['ixParent'])andnot(src_repo['ixParent']inrepo_map)):q.put(src_repo)debug_print(" Postponing work on Repository '%s'"%(src_repo['sName']))continuedebug_print(" Working on Repository '%s'"%(src_repo['sName']))# If the old repository had a parent, add the assocation to the old_parent_associations list#if src_repo['ixParent']:# old_parent_associations += [(src_repo['ixRepo'], src_repo['ixParent'])] # add (old_ixrepo, old_parent_ixrepo) to the listdest_repo=None# Try to find the project on the Destination Serverdest_repos=dest_repo_group['repos']fora_dest_repoindest_repos:if(a_dest_repo['sName']==src_repo['sName']):dest_repo=json.load(urllib2.urlopen('%s/Api/1.0/Repo/%s?token=%s'%(destinationServer,a_dest_repo['ixRepo'],destinationToken)))debug_print(" - Found an existing match on the destination server. ixRepo = %s"%(dest_repo['ixRepo']))debug_print(" - DESTINATION REPOSITORY DATA:\n"+str(dest_repo),2) # If we don't find an existing repo, then create a new repo with the information we grabbed from the old server
if (not dest_repo):
if (src_repo['ixParent']):
+ # By setting the ixParent field, when Repo/Create is called, it will create a new branch from the ixParent Repo.+ # This means, that the point at which the src repo branched off from the parent can and most likely will be different from the + # point at which the dest repo gets branched. (One option I know of to fix this, after the fact, is to strip changesets in + # the dest repo back to the point where the branch was created in the src repo. Then push the src repo to the dest repo and + # the src and dest branches should be back in sync.+ debug_print(" !!! Warning: Branches may not migrate properly !!!") data = urllib.urlencode({'token': destinationToken,
'sName': src_repo['sName'],
'sDescription': src_repo['sDescription'],
'ixRepoGroup':dest_repo_group['ixRepoGroup'],'permissionDefault':src_repo['permissionDefault'],'ixParent':repo_map[src_repo['ixParent']],'fCentral':'false'})else:data=urllib.urlencode({'token':destinationToken,'sName':src_repo['sName'],'sDescription':src_repo['sDescription'],'ixRepoGroup':dest_repo_group['ixRepoGroup'],'permissionDefault':src_repo['permissionDefault']})dest_repo=json.load(urllib2.urlopen('%s/Api/1.0/Repo/Create/'%(destinationServer),data))debug_print(" + Created a new Repository on the destination server. ixRepo = %s"%(dest_repo['ixRepo']))debug_print(" + DESTINATION REPOSITORY DATA:\n"+str(dest_repo),2)# Record the mapping from the old server to the new server. repo_map[oldIxRepo] = newIxReporepo_map[src_repo['ixRepo']]=dest_repo['ixRepo']# Build a unique folder name to clone the repo intofolder_name=src_repo['sName']+"-"+str(src_repo['ixRepo'])# Convert empty RepoGroup slug values to the default 'Group'group_name=src_repo_group['sSlug']if(group_name==''):group_name='Group'new_group_name=dest_repo_group['sSlug']if(new_group_name==''):new_group_name='Group'# Clone the repo locally, and then push it to the destination serveros.system("hg clone "+sourceServer+'/Code/'+src_project["sSlug"]+'/'+group_name+'/'+src_repo["sSlug"]+' "'+folder_name+'"')os.chdir(folder_name)os.system("hg push "+destinationServer+'/Code/'+dest_project["sSlug"]+'/'+new_group_name+'/'+dest_repo["sSlug"])os.chdir('..')debug_print("\nDONE!")
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.