Sunday, August 16, 2009

Backing up 'My Pictures'

I use Picasa to manage my pictures, all of them. The problem I have and a preference is that while I keep some of them on my laptop, which is backed up weekly, I'd like the bulk of them archived to my external drives.

The following is a batch file (.CMD) that will archive my files from my laptop to my "T:" drive, then back up that collection, complete to my "G:" drive. It also tries to process the Picasa Album databases, but I'm not sure this is working ideally yet. When running this batch file ensure Picasa is not running, and relax.
@echo off
CLS
SET backupDest1=T:\Archive of My Pictures
SET backupDest2=G:\Backup of My Pictures
TITLE Backup Up Picasa Album Settings...
FOR /F "tokens=1,2,3,4,5 delims=/ " %%a in ('date /T') do SET backupDate=%%c%%b%%a
PUSHD "%USERPROFILE%\Local Settings\Application Data\Google\Picasa2Albums\"
IF NOT EXIST "%backupDest1%" MKDIR "%backupDest1%"
IF NOT EXIST "%backupDest1%\_AlbumInfo" MKDIR "%backupDest1%\_AlbumInfo"
IF NOT EXIST "%backupDest1%\_AlbumInfo\%backupDate%" MKDIR "%backupDest1%\_AlbumInfo\%backupDate%"
robocopy backup "%backupDest1%\_AlbumInfo\backup" *.* /XO /S /E /ETA /V /R:3 /W:3
robocopy . "%backupDest1%\_AlbumInfo\%backupDate%" *.* /XO /XD backup /S /E /ETA /V /R:3 /W:3
TITLE Updating Album File Locations...
FOR /F "tokens=1,2,3,4,5 delims=:" %%a in ('echo %backupDest1%') do SET myPicsUpdate=[%%a]%%b
FOR /F %%a in ('dir /b /a:d-h "%backupDest1%\_AlbumInfo\%backupDate%\"') do call :cmpAInfo "%backupDest1%\_AlbumInfo\%backupDate%\%%a"
TITLE Clearing My Pictures...
robocopy "%USERPROFILE%\My Documents\My Pictures" "%backupDest1%" /S /E /ETA /MOVE /R:3 /W:3
TITLE Backing up %backupDest1% to %backupDest2%...
robocopy "%backupDest1%" "%backupDest2%" /XO /S /E /ETA /V /R:3 /W:3
TITLE Update Active Albums...
robocopy "%backupDest1%\_AlbumInfo\%backupDate%" . *.* /XO /XD backup /S /E /ETA /V /R:3 /W:3
if NOT EXIST "%USERPROFILE%\My Documents\My Pictures" MKDIR "%USERPROFILE%\My Documents\My Pictures"
popd
goto :eof
pause
TITLE Command Prompt
goto :eof

:cmpAInfo
echo Processing %~1...
REM FOR /F %%a in ('dir /b "%~1"') do echo "%~1\%%a"
FOR /F %%a in ('dir /b /a:-d "%~1"') do gsar -i -o -s"$My Pictures" -r"%myPicsUpdate%" "%~1\%%a"
goto :eof

Now... you'll need to verify your date format at the command prompt, mine is DD/MM/YYYY the line that sets the backupDate may need to be tweaked. Of course the two destination variables need to be set appropriately for your own needs. Have fun... but play it safe test this for yourself first.

gsar.exe - Global Search and Replace
robocopy - Microsoft's Robocopy


There is no individual ownership when you are part of a team, it's the sum of the parts that makes you the RESILIENT team you need to be.