Tuesday, October 25, 2011

Repairing 'svnsync: malformed file' error with subversion


I recently had a sync or other failure of svnsync which left me with a bum repository. Every time we tried to do svnsync, it reported "svnsync: malformed file." I got the same error with all svnadmin access.

I found this link: http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=1892873&orderBy=createDate&orderType=desc and provided some good clues. I noticed that my file in db\revprops\0 had junk in it instead of normal stuff. It should have looked like this:

K 8
svn:date
V 27
2010-07-21T02:55:12.203323Z
K 17
svn:sync-from-url
V 45
https://portal.secureci.com/svn/secureci
K 18
svn:sync-from-uuid
V 36
b443ad56-1e36-4a4f-97ef-7144cc153033
K 24
svn:sync-last-merged-rev
V 1
0
END


What I did to fix it:

  • cd c:/temp
  • svnadmin create svn-sync2
  • Copy hooks/pre-revprop-change.bat file from broken repository to new one
  • svnsync --username svnsync initialize file:///c:/temp/svn-sync2 https://portal.secureci.com/svn/securci
  • Copy the db/revprops/0/0 file from the new repos to the broken one
  • Edit the 0 file and fix the 'sync-last-merged-rev' entry to have the correct number.
    • Look in db/revprops/2 (or highest number) and locate the most recent numbered file (e.g., 2437)
    • Change '0' value below "V 1" to be "2437"
    • Change the V1 line to be "V 4" for 4 character length
  • Run 'svnadmin verify .' in the main directory of your broken repository to make sure that it has everything intact. (This may take a little while.)
  • Run 'svnsync --username svnsync synchronize file:///c:/SecureCIdata/svn/repos/secureci' and make sure synchronization goes smoothly
That's it. Syncing should work normally now.

Wednesday, October 5, 2011

DOS batch file stderr redirection

I never remember the whether the syntax of DOS file redirection is similar to normal Unix file redirection. It is. So I'm writing it down where I can find it.

CALL .\somescript.bat >> logfile.log 2>&1

Of note, I recently learned that redirecting output from a PowerShell script does NOT work very well and gives file handle errors. That's another story, entirely.

Common DOS batch file error handling mistakes I make

I write a decent amount of batch scripts now days to automate things on windows server boxes. Unfortunately, I don't do it quite frequently enough to remember all the crazy syntax of DOS commands. One of these errors is error handling. These are the things I commonly need to deal with.

I found this page (and site) very helpful for all DOS related stuff: http://www.robvanderwoude.com/errorlevel.php

  1. Use "IF %ERRORLEVEL% NEQ 0 SET MYERROR=1" to record whether the previous command resulted in an error code. Alternately, you can check for "IF ERRORLEVEL 1 ..." if you want to look for a specific error level.
  2. Be cautious of manipulations with ERRORLEVEL. It's not really an environment variable like other variables. In particular, do NOT ever use "set ERRORLEVEL=5" or similar. It will corrupt any further use of %ERRORLEVEL% syntax by fixing it at a value.
  3. Use "CALL FOO.BAT" instead of just "FOO.BAT" when calling subscripts. Otherwise, when that script completes it will not return to the current script.
  4. Use "EXIT /B 1" to return an exit code from your script. If you use "EXIT 1" it will exit the entire command shell, including closing your current window if it's running in one.
  5. Consider using SETLOCAL and ENDLOCAL within your script to prevent temporary environment variables from carrying through to outer shells.

Below is an example script.


:: Sample script with some error handling
SETLOCAL
SET MYPARAM=%1
if "%MYPARAM%"=="" goto :USAGE

CALL .\childscript.bat %MYPARAM%
if %ERRORLEVEL% NEQ 0 set MYERROR=1

echo.
echo Finished child script. Handling errors now...

if %MYERROR%==1 GOTO :ERROR

echo It worked!
ENDLOCAL
set SOME_EXTERNAL_VARIABLE=1


GOTO :EOF
:USAGE
echo Please provide a command line parameter.
EXIT /B 2


:ERROR
echo It didn't work, dude.
EXIT /B 1 

Update: I was wrong about the ERRORLEVEL syntax earlier, so I updated after some testing.

Monday, October 3, 2011

Change Windows 7 default logon screen background

When you change your desktop background in Windows 7, it does not change the background for the logon screen. Since I have multiple machines connected to a KVM on my setup, I like to have different colors to signify which machine I'm actually looking at.

Windows 7 doesn't provide a good mechanism through the UI for changing this. To do it, you need to change a registry key and store your background as the correct file.

I found this post which was helpful: http://www.kodyaz.com/articles/change-windows-7-logon-screen-background-using-registry-oobe.aspx

Bascially,
  1. Navigate to this registry key path with regedit.exe: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\
    Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background
  2. Make sure the OEMBackground DWORD key is set to 1.
  3. Navigate to C:\Windows\System32\oobe\info\backgrounds directory
  4. There will probably already be a bunch of backgrounds there. Pick the one you want and save it as 'backgrounddefault.jpg'
That's it. You're done. Hit Windows-L to lock your screen and you should see the new background file.