Showing posts with label synchronization. Show all posts
Showing posts with label synchronization. Show all posts

Wednesday, December 01, 2010

Dropbox Sync Script

Recently, I started using Steam, and while Steam can install each of your games on each of your computers, it doesn't keep the game saves in sync.  I wanted to be able to pick up where I had left off on any computer I wanted, not needing to worry about copying over save files, so I turned to Dropbox, which I've been using for a while. 

I had created a set of batch scripts that I used on Windows to set up the sync folders, but since I was adding several folders, and the number of scripts was getting to be large, I decided to combine them all into a single flexible and streamlined script.  I also decided to make it as generic as possible, so that other people could use it with minimal fuss.  Basically the script has a function that moves files and folders located outside of the Dropbox folder inside, and then creates a symlink (or folder junction), so that the program accessing the files doesn't need to be reconfigured in order to keep accessing the files.  If the item is already in the Dropbox folder, the original is kept under a different name, and a link is created to the existing synced content.  If the item doesn't exist in either place, it gets created in Dropbox, and linked to in the specified location.

The script is populated with things that I want synced, which will probably be different from what you want to sync, but it should be a simple matter to change that.  If you add items, the script is set up so that you can re-run it without creating more and more symlinks.

It's worth noting that the mklink command requires Windows Vista or later.  If you're running an earlier version such as XP, it will use the linkd command, which comes with the Windows 2003 Resource Kit. (You don't need to be running 2003 to install it.)

So, without further ado, here is the script:
@echo off
:: This script creates symlinks (NTFS junctions) in order to sync the contents via Dropbox
:: Some of these items require Administrator privileges to execute because of where the items are located.

:: Copyright 2010 Tim "burndive" of http://burndive.blogspot.com/ and http://tuxbox.blogspot.com/
:: This software is licensed under the Creative Commons GNU GPL version 2.0 or later.
:: License informattion: http://creativecommons.org/licenses/GPL/2.0/
:: This script was obtained from here:
:: http://tuxbox.blogspot.com/2010/12/dropbox-sync-script.html

:: Set this to your Steam user ID
set STEAM_USER=burndive

:: The path to your Documents folder
set DOCUMENTS=%USERPROFILE%\My Documents
if exist "%USERPROFILE%\Documents" (
  set DROPBOX=%USERPROFILE%\Documents
)

:: The path to your Dropbox folder
set DROPBOX=%DOCUMENTS%\My Dropbox
if exist "%USERPROFILE%\Dropbox" (
  set DROPBOX=%USERPROFILE%\Dropbox
)

:: Determine which command to use for making Folder Junctions
ver | findstr "5." > nul
if errorlevel 1 (
  :: This requires Windows Vista or later
  set JUNCTION_CMD=mklink /j
) else (
  :: This requires the Windows 2003 Resource Kit Tools
  set JUNCTION_CMD=linkd
)

:: Find the correct Flash SharedObjects folder name if localhost subfolder exists
set FLASH_LOCAL=
for /F "tokens=*" %%I in ('dir /b "%APPDATA%\Macromedia\Flash Player\#SharedObjects"') do (
  if exist "%APPDATA%\Macromedia\Flash Player\#SharedObjects\%%I\localhost" (
    set FLASH_LOCAL=%APPDATA%\Macromedia\Flash Player\#SharedObjects\%%I\localhost
  )
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: The following items require only User privileges to execute
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: Make localhost Flash Shared Objects dir architecture neutral
if not "%FLASH_LOCAL%" == "" (
  if exist "%FLASH_LOCAL%\Program Files (x86)" (
    call:LinkFolder "%FLASH_LOCAL%", "Program Files", "%FLASH_LOCAL%\Program Files (x86)"
  )
)

:: Digital Blasphemy wallpapers
call:LinkFolder "%USERPROFILE%\Pictures\wallpaper", "db-fs", "%DROPBOX%\images\digital-blasphemy\db-fs"
call:LinkFolder "%USERPROFILE%\Pictures\wallpaper", "db-ws", "%DROPBOX%\images\digital-blasphemy\db-ws"
call:LinkFolder "%USERPROFILE%\Pictures\wallpaper", "db-preview", "%DROPBOX%\images\digital-blasphemy\db-preview"

:: Images
call:LinkFolder "%USERPROFILE%\Pictures", "images", "%DROPBOX%\images"

:: Pidgin Instant Messenger
call:LinkFolder "%APPDATA%\.purple", "icons", "%DROPBOX%\app-files\pidgin\icons"
call:LinkFolder "%APPDATA%\.purple", "logs", "%DROPBOX%\app-files\pidgin\logs"

:: DVRMSToolbox Commercials XML files
call:LinkFolder "%PUBLIC%\DvrmsToolbox", "CommercialsXml", "%DROPBOX%\app-files\CommercialsXml"

::::::::::::::::::::::
:: Humble Bundle Games
::::::::::::::::::::::
:: Penumbra Overture
call:LinkFolder "%DOCUMENTS%\Penumbra Overture\Episode1", "save", "%DROPBOX%\app-files\game-saves\penumbra-overture"
:: Samarost2 : TODO
:: World of Goo
call:LinkFolder "%LOCALAPPDATA%\2DBoy", "WorldOfGoo", "%DROPBOX%\app-files\game-saves\world-of-goo"
:: Aquaria : TODO
:: Gish : TODO
:: Lugaru : TODO

::::::::::::::::::::::::
:: Humble Bundle 2 Games
::::::::::::::::::::::::
:: Braid
call:LinkFolder "%APPDATA%", "Braid", "%DROPBOX%\app-files\game-saves\braid"
:: Machinarium
if not "%FLASH_LOCAL%" == "" (
  if exist "%FLASH_LOCAL%\Program Files" (
    call:LinkFolder "%FLASH_LOCAL%\Program Files\Machinarium", "machinarium.exe", "%DROPBOX%\app-files\game-saves\machinarium"
  )
)
:: Osmos
call:LinkFolder "%DOCUMENTS%", "Osmos", "%DROPBOX%\app-files\game-saves\osmos"
:: Cortex Command : TODO
:: Revenge of the Titans HIB
call:LinkFolder "%USERPROFILE%\Revenge of the Titans 1.71", "slots", "%DROPBOX%\app-files\game-saves\revenge-of-the-titans-1.71"
call:LinkFolder "%USERPROFILE%\Revenge of the Titans 1.72", "slots", "%DROPBOX%\app-files\game-saves\revenge-of-the-titans-1.72"

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: The following items require Administrator privileges to execute
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: Eclipse workspace
call:LinkFolder "%USERPROFILE%", "workspace", "%DROPBOX%\app-files\workspace"

:: gVim config file
call:LinkFile "%USERPROFILE%", "_gvimrc", "%DROPBOX%\config\windows\_gvimrc"

:: Steam Game save folders
if exist "%PROGRAMFILES(X86)%" (
  :: Note: The caret is an escape character
  set STEAM_DIR=C:\Program Files ^(x86^)\Steam\steamapps
) else (
  set STEAM_DIR=%PROGRAMFILES%\Steam\steamapps
)
call:LinkFolder "%STEAM_DIR%\%STEAM_USER%\half-life 2\hl2", "SAVE", "%DROPBOX%\app-files\game-saves\half-life-2-steam"
call:LinkFolder "%STEAM_DIR%\%STEAM_USER%\half-life 2 episode one\episodic", "SAVE", "%DROPBOX%\app-files\game-saves\half-life-2-ep1-steam"
call:LinkFolder "%STEAM_DIR%\%STEAM_USER%\half-life 2 episode two\ep2", "SAVE", "%DROPBOX%\app-files\game-saves\half-life-2-ep2-steam"
call:LinkFolder "%STEAM_DIR%\%STEAM_USER%\half-life 2 lostcoast\lostcoast", "SAVE", "%DROPBOX%\app-files\game-saves\half-life-2-lostcoast-steam"
call:LinkFolder "%STEAM_DIR%\%STEAM_USER%\portal\portal", "SAVE", "%DROPBOX%\app-files\game-saves\portal-steam"

:: Pause so the user can review output
pause

:: End of execution
goto:eof

::::::::::::
:: Functions
::::::::::::

:LinkFolder
setlocal
:: Arguments
set LINK_PATH=%~1
set LINK_NAME=%~2
set TARGET=%~3
::echo Link: %LINK_PATH%\%LINK_NAME%
::echo Target: %TARGET%

if not exist "%LINK_PATH%" (
  mkdir "%LINK_PATH%"
)
cd "%LINK_PATH%"
:: If the folder is already a link, just delete it
dir | findstr /i "%LINK_NAME%" | findstr "<JUNCTION>" > NUL
if not errorlevel 1 (
  rmdir "%LINK_NAME%"
)
if exist "%LINK_NAME%" (
  if exist "%TARGET%" (
    echo Backing up conflicting copy
    move "%LINK_NAME%" "%LINK_NAME%-orig"
  ) else (
    :: Move the original if target does not exist
    echo Moving original folder to link location
    echo move "%LINK_NAME%" "%TARGET%"
    move "%LINK_NAME%" "%TARGET%"
  )
) else (
  if not exist "%TARGET%" (
    :: If neither exist, create target
    echo Creating target folder
    mkdir "%TARGET%"
  )
)
%JUNCTION_CMD% "%LINK_NAME%" "%TARGET%"

endlocal
goto:eof

:LinkFile
setlocal
:: Arguments
set LINK_PATH=%~1
set LINK_NAME=%~2
set TARGET=%~3
::echo Link: %LINK_PATH%\%LINK_NAME%
::echo Target: %TARGET%

if not exist "%LINK_PATH%" (
  mkdir "%LINK_PATH%"
)
cd "%LINK_PATH%"
:: If the folder is already a link, just delete it
dir | findstr /i "%LINK_NAME%" | findstr "<SYMLINK>" > NUL
if not errorlevel 1 (
  del "%LINK_NAME%"
)
if exist "%LINK_NAME%" (
  if exist "%TARGET%" (
    echo Backing up conflicting copy
    move "%LINK_NAME%" "%LINK_NAME%-orig"
  ) else (
    :: Move the original if target does not exist
    echo Moving original file to target location
    move "%LINK_NAME%" "%TARGET%"
  )
) else (
  if not exist "%TARGET%" (
    :: If neither exist, create target
    echo Creating empty target file
    echo "" > "%TARGET%"
  )
)
:: linkd will not work for files, only folders
mklink "%LINK_NAME%" "%TARGET%"

endlocal
goto:eof
CC-GNU GPL
This software is licensed under the CC-GNU GPL version 2.0 or later.

PS: If you use my code, I appreciate comments to let me know, and any feedback you may have, especially if it's not working right for you, but also just to say thanks.

For convenience, you can download this script from my server.

Tuesday, October 05, 2010

My Take on Windows Live Essientials

Microsoft just released their Live Essentials suite of software downloads for Vista and Windows 7 machines.  I've been using them since January 2009.  Here are my thoughts.

You shouldn't install them all, first of all.  When you download and run the installer, you get the choice to install everything, or pick and choose.  Make the latter selection.  If you have a previous version of something, they won't give you the choice not to upgrade, so if there's something you don't want to install, quit the installer and uninstall it first.
Which programs in particular to install will be an individual choice.  I already had Mail, Writer, Photo Gallery, and Windows Live Mesh installed from the beta.  I had installed Microsoft Office since last updating the software, and so the installer offered me the "Outlook Connecter Pack".  I'm not sure what it is, but it probably won't hurt.

Speaking of hurt, though, unless you really, really want it, don't install the Bing Bar.  It's just a bad idea.  It will try to take over all of your browsers, and seriously, who needs a toolbar in their browser? 
 
I've never tried the updated Messenger, Messenger Companion, or Family Safety.  I hardly ever use my hotmail account to chat, and I use Pidgin when I do, so I don't really have a use for the Messenger enhancements.

Writer is apparently a very good blogging tool that works with a lot of popular blogging sites (like Blogger, which hosts this blog), but so far, I've stuck with the web interface for composition.
By far the most useful tool is Windows Live Mesh.  If you're like me, you have a bunch of pictures, music, files, and other documents on various computers.  The file sets are simply too large to fit into a free Dropbox account, and you don't really need access to them over the web, at least not most of them, you just want them on your various computers.  It's a hassle to keep all of photos or music organized in more than one place, so you don't.  You keep them organized in one place, and (hopefully) make periodic backups to another computer just in case. Well, Live Mesh allows you to keep it organized the way you want it, everywhere you want it, and it doesn't matter how big the files are, because Microsoft isn't going to store any of them (except for a special 5GB folder, which it will store in the cloud and allow you to access from anywhere on the web.)

Microsoft doesn't upload your files to its servers, but it does keep track of them for you.  Any change you make to your shared folders gets copied to the other computers where that folder is synced, and the copying is peer-to-peer, so if you're at home, it happens at the speed of your home network.  It will also keep your files in sync even if you're not at home, directly from your other computer, not through their servers.

The management interface is pretty simple, though it's easy to miss the "Remote" settings, which allow you to connect to your computer over the Internet if you have enabled it on that device.  Connect is a lot like Remote Desktop, if you're familiar with that.  Basically, it's just like you're sitting at the other computer.  You have to be running MSIE on the computer you're connecting from.

The web interface is a lot like the desktop interface, except in addition to your shared folders, you also have access to all of your devices as well, and you can see which devices sync to each of your folders.

Update:  After installing  Windows Live Mesh on my wife's new netbook, she experienced extremely slow performance.  Her netbook has a 2GHz x64 processor and 2GB of ram, so it wasn't simply the fact that it was a netbook that was making it slow.  I opened Task Manager, and found that the MOE process ("Mesh Operating Environment") was consistently taking up 40 - 60% of the CPU.  I shut down the process, and deleted the "Run" entry from the registry to disable it starting up automatically.  Any syncing that happens will need Live Mesh to be started manually.  I also observed similar behavior on my laptop, but the media PC (which is on all the time) has the MOE process taking only 3 - 5% of the CPU.  It's probably checking the synced files for updates every time it starts up.

Anyway, be warned: Windows Live Mesh is a resource hog on machines that need to turn on and off all the time.

Wednesday, January 13, 2010

Dropbox: File Synchronization

Ever since we got our second computer (back in 1998, I believe), I have been dealing with the problem of how to keep my files in sync between multiple computers.  Initially, I simply didn't, or I used floppy disks to move files back and forth.  Then I bought an Ethernet hub, and used windows shares to pass the data back and forth.  When I bought a CD burner, I would periodically create snapshots of the family's files.

Over the years, I have had many hard drives crash, and many more clean installs.  Solving the file sync problem is often best accomplished in conjunction with backing up those files.

Until recently, I still basically used the LAN solution:  Keep two copies of my files on different computers, and periodically (or sporadically) copy one set of files over the other.  Of course, if you do it this way, you can never change your directory structure, or you have duplicates, and when you try to clean up the duplicates, you lose files.

I also back up important files weekly to an external drive, and I keep four weekly backups, plus six monthly backups.  This process is automated thanks to a customized version of a backup script and some cron jobs on my Linux box.  This part hasn't changed.

Recently, however, I discovered a handy little service called Dropbox.  Dropbox will back up your files, keep them in sync on all of your computers (2 GB for free, pay for more), and enable you to share them with other users if you choose.  I've tried Windows Live Mesh, and I still might use that for remote login, but Dropbox gives you more free storage space, and it is able to sync files from one computer to another over a local LAN (which saves ISP bandwidth).  Also, Dropbox supports Linux, which is a must for me.

[Note: if you want to sign up, use my Dropbox referral link an we'll both get an extra 250MB of free space.]

Dropbox enables some pretty cool syncing tricks if you're willing to roll up your sleeves at the command line.  Here are a few things I'm doing:
  • The Linux client for Dropbox treats symlinks to folders as if they were just folders.  Initially, I didn't like this, because it meant I couldn't just plop my existing file structure in place (because it contained symlinks to large data sets in other locations).  Also, I didn't want certain directories synced.  My solution was to simply link to the things I want to sync from my Dropbox folder.  That way, I can structure my directories any way I want, and cherry-pick the things I want to sync from that structure.


  • I use the Pidgin client for all my Instant Messaging accounts on Windows and Linux.  Pidgin logs all of my conversations, and saves them to a local folder.  Whenever someone IMs me or I open a chat window to IM someone else, the chat window is automatically populated with the latest conversation with that person from the chat log history.  In order to synchronize these logs between computers I created a symlink in the Dropbox folder to the logs folder on my Linux box.  In order to get my Windows pidgin accounts to use this folder, I created a folder "Junction" within the Pidgin AppData folder (.purple) using the command: "mklink /J".


  • I use DVRMSToolbox along with ShowAnalyzer to automatically find and skip commercials in Windows Media Center.  ShowAnalyzer is run on our living room media PC, and that is where the files are stored that tell the DTBAddin component where the commercials are within a given recorded TV file.  (If you're interested in setting this up yourself, see this guide.)  Normally, I would have to periodically copy new files in the CommercialsXml folder from C:\Public\Users\DvrmsToolbox on the media PC to my laptop in order for my laptop to know when to skip a commercial.  Now, the files are synced automatically, and I don't have to think about them.  I just open my laptop, fire up Media Center, and select the show I want to watch.  It's a pretty sweet setup.



Thursday, May 07, 2009

Software To Install On A Windows Box

With the Windows 7 release candidate out, I recently wiped my laptop's hard drive clean and installed it (I was previously running beta 2). Whenever I flatten a computer and re-install everything fresh, I like to have a list of things to install that covers the bases.

I put together a bookmarks folder of software to install on a new Windows box, and I decided to share it with the world, so here it is:
The nice thing about sharing it in this way is that I can keep it up-to-date in my browser if there is anything to add or remove, or if any of the links change.

Enjoy.